Completed
Branch FET-10768-extract-admin-bar (46d5db)
by
unknown
119:49 queued 108:29
created
core/db_models/EEM_Event.model.php 3 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php use EventEspresso\core\services\orm\ModelFieldFactory;
1
+<?php 
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
Please login to merge, or discard this patch.
Indentation   +767 added lines, -767 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\orm\ModelFieldFactory;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
7 7
 
@@ -18,772 +18,772 @@  discard block
 block discarded – undo
18 18
 class EEM_Event extends EEM_CPT_Base
19 19
 {
20 20
 
21
-    /**
22
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
23
-     * event
24
-     */
25
-    const sold_out = 'sold_out';
26
-
27
-    /**
28
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
29
-     * date)
30
-     */
31
-    const postponed = 'postponed';
32
-
33
-    /**
34
-     * constant used by status(), indicating that the event will no longer occur
35
-     */
36
-    const cancelled = 'cancelled';
37
-
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected static $_default_reg_status;
43
-
44
-
45
-    /**
46
-     * This is the default for the additional limit field.
47
-     * @var int
48
-     */
49
-    protected static $_default_additional_limit = 10;
50
-
51
-
52
-    /**
53
-     * private instance of the Event object
54
-     *
55
-     * @var EEM_Event
56
-     */
57
-    protected static $_instance;
58
-
59
-
60
-
61
-
62
-    /**
63
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
64
-     *
65
-     * @param string $timezone
66
-     * @throws \EE_Error
67
-     */
68
-    protected function __construct($timezone = null)
69
-    {
70
-        EE_Registry::instance()->load_model('Registration');
71
-        $this->singular_item = esc_html__('Event', 'event_espresso');
72
-        $this->plural_item = esc_html__('Events', 'event_espresso');
73
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
74
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
75
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
76
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
77
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
78
-        //	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
79
-        $this->_custom_stati = apply_filters(
80
-            'AFEE__EEM_Event__construct___custom_stati',
81
-            array(
82
-                EEM_Event::cancelled => array(
83
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
84
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
85
-                ),
86
-                EEM_Event::postponed => array(
87
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
88
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
89
-                ),
90
-                EEM_Event::sold_out  => array(
91
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
92
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
93
-                ),
94
-            )
95
-        );
96
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
97
-            : self::$_default_reg_status;
98
-        $this->_tables = array(
99
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
100
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
101
-        );
102
-        $this->_fields = array(
103
-            'Event_CPT'  => array(
104
-                'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
105
-                    esc_html__('Post ID for Event', 'event_espresso')),
106
-                'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
107
-                    false,
108
-                    ''),
109
-                'EVT_desc'       => new EE_Post_Content_Field('post_content',
110
-                    esc_html__('Event Description', 'event_espresso'),
111
-                    false, ''),
112
-                'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
113
-                    ''),
114
-                'EVT_created'    => new EE_Datetime_Field('post_date',
115
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
116
-                    false, EE_Datetime_Field::now),
117
-                'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
118
-                    esc_html__('Event Short Description', 'event_espresso'), false, ''),
119
-                'EVT_modified'   => new EE_Datetime_Field('post_modified',
120
-                    esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
121
-                'EVT_wp_user'    => new EE_WP_User_Field('post_author',
122
-                    esc_html__('Event Creator ID', 'event_espresso'),
123
-                    false),
124
-                'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
125
-                    false,
126
-                    0),
127
-                'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
128
-                    false,
129
-                    1),
130
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
131
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
132
-                'status'         => new EE_WP_Post_Status_Field('post_status',
133
-                    esc_html__('Event Status', 'event_espresso'),
134
-                    false, 'draft', $this->_custom_stati),
135
-            ),
136
-            'Event_Meta' => array(
137
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
138
-                    esc_html__('Event Meta Row ID', 'event_espresso'), false),
139
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
140
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
141
-                'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
142
-                    esc_html__('Display Description Flag', 'event_espresso'), false, 1),
143
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
144
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
145
-                'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
146
-                    esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
147
-                'EVT_additional_limit'            => new EE_Integer_Field(
148
-                    'EVT_additional_limit',
149
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
150
-                    true,
151
-                    self::$_default_additional_limit
152
-                ),
153
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
154
-                    'EVT_default_registration_status',
155
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
156
-                    EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
157
-                ),
158
-                'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
159
-                    esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
160
-                'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
161
-                    esc_html__('Event Phone Number', 'event_espresso'), false),
162
-                'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
163
-                    esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
164
-                'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
165
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false),
166
-                'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
167
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
168
-                'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
169
-                    esc_html__('Accept Donations?', 'event_espresso'), false, false),
170
-            ),
171
-        );
172
-        $this->_model_relations = array(
173
-            'Registration'           => new EE_Has_Many_Relation(),
174
-            'Datetime'               => new EE_Has_Many_Relation(),
175
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
176
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
177
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
178
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
179
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
180
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
181
-            'WP_User'                => new EE_Belongs_To_Relation(),
182
-        );
183
-        //this model is generally available for reading
184
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
185
-        parent::__construct($timezone);
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * @param string $default_reg_status
192
-     */
193
-    public static function set_default_reg_status($default_reg_status)
194
-    {
195
-        self::$_default_reg_status = $default_reg_status;
196
-        // if EEM_Event has already been instantiated,
197
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
198
-        if (self::$_instance instanceof EEM_Event) {
199
-            $default_reg_status = new EE_Enum_Text_Field(
200
-                'EVT_default_registration_status',
201
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
202
-                false,
203
-                $default_reg_status,
204
-                EEM_Registration::reg_status_array()
205
-            );
206
-            $default_reg_status->_construct_finalize(
207
-                'Event_Meta',
208
-                'EVT_default_registration_status',
209
-                'EEM_Event'
210
-            );
211
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * Used to override the default for the additional limit field.
218
-     * @param $additional_limit
219
-     */
220
-    public static function set_default_additional_limit($additional_limit)
221
-    {
222
-        self::$_default_additional_limit = (int) $additional_limit;
223
-        if (self::$_instance instanceof EEM_Event) {
224
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
225
-                'EVT_additional_limit',
226
-                __('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
227
-                true,
228
-                self::$_default_additional_limit
229
-            );
230
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
231
-                'Event_Meta',
232
-                'EVT_additional_limit',
233
-                'EEM_Event'
234
-            );
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * Return what is currently set as the default additional limit for the event.
241
-     * @return int
242
-     */
243
-    public static function get_default_additional_limit()
244
-    {
245
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
246
-    }
247
-
248
-
249
-    /**
250
-     * get_question_groups
251
-     *
252
-     * @return array
253
-     * @throws \EE_Error
254
-     */
255
-    public function get_all_question_groups()
256
-    {
257
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
258
-            array(
259
-                array('QSG_deleted' => false),
260
-                'order_by' => array('QSG_order' => 'ASC'),
261
-            )
262
-        );
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * get_question_groups
269
-     *
270
-     * @param int $EVT_ID
271
-     * @return array|bool
272
-     * @throws \EE_Error
273
-     */
274
-    public function get_all_event_question_groups($EVT_ID = 0)
275
-    {
276
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
277
-            EE_Error::add_error(
278
-                esc_html__(
279
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
280
-                    'event_espresso'
281
-                ),
282
-                __FILE__, __FUNCTION__, __LINE__
283
-            );
284
-            return false;
285
-        }
286
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
287
-            array(
288
-                array('EVT_ID' => $EVT_ID),
289
-            )
290
-        );
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * get_question_groups
297
-     *
298
-     * @param int     $EVT_ID
299
-     * @param boolean $for_primary_attendee
300
-     * @return array|bool
301
-     * @throws \EE_Error
302
-     */
303
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
304
-    {
305
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
306
-            EE_Error::add_error(
307
-                esc_html__(
308
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
309
-                    'event_espresso'
310
-                ),
311
-                __FILE__, __FUNCTION__, __LINE__
312
-            );
313
-            return false;
314
-        }
315
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
316
-            array(
317
-                array(
318
-                    'EVT_ID'      => $EVT_ID,
319
-                    'EQG_primary' => $for_primary_attendee,
320
-                ),
321
-            )
322
-        );
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * get_question_groups
329
-     *
330
-     * @param int             $EVT_ID
331
-     * @param EE_Registration $registration
332
-     * @return array|bool
333
-     * @throws \EE_Error
334
-     */
335
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
336
-    {
337
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
338
-            EE_Error::add_error(
339
-                esc_html__(
340
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
341
-                    'event_espresso'
342
-                ),
343
-                __FILE__, __FUNCTION__, __LINE__
344
-            );
345
-            return false;
346
-        }
347
-        $where_params = array(
348
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
349
-            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
350
-            'QSG_deleted'                      => false,
351
-        );
352
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
-            array(
354
-                $where_params,
355
-                'order_by' => array('QSG_order' => 'ASC'),
356
-            )
357
-        );
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * get_question_target_db_column
364
-     *
365
-     * @param string $QSG_IDs csv list of $QSG IDs
366
-     * @return array|bool
367
-     * @throws \EE_Error
368
-     */
369
-    public function get_questions_in_groups($QSG_IDs = '')
370
-    {
371
-        if (empty($QSG_IDs)) {
372
-            EE_Error::add_error(
373
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
374
-                __FILE__, __FUNCTION__, __LINE__
375
-            );
376
-            return false;
377
-        }
378
-        return EE_Registry::instance()->load_model('Question')->get_all(
379
-            array(
380
-                array(
381
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
382
-                    'QST_deleted'           => false,
383
-                    'QST_admin_only'        => is_admin(),
384
-                ),
385
-                'order_by' => 'QST_order',
386
-            )
387
-        );
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * get_options_for_question
394
-     *
395
-     * @param string $QST_IDs csv list of $QST IDs
396
-     * @return array|bool
397
-     * @throws \EE_Error
398
-     */
399
-    public function get_options_for_question($QST_IDs)
400
-    {
401
-        if (empty($QST_IDs)) {
402
-            EE_Error::add_error(
403
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
404
-                __FILE__, __FUNCTION__, __LINE__
405
-            );
406
-            return false;
407
-        }
408
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
409
-            array(
410
-                array(
411
-                    'Question.QST_ID' => array('IN', $QST_IDs),
412
-                    'QSO_deleted'     => false,
413
-                ),
414
-                'order_by' => 'QSO_ID',
415
-            )
416
-        );
417
-    }
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-    /**
426
-     * Gets all events that are published
427
-     * and have event start time earlier than now and an event end time later than now
428
-     *
429
-     * @param  array $query_params An array of query params to further filter on
430
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
431
-     * @param bool   $count        whether to return the count or not (default FALSE)
432
-     * @return EE_Event[]|int
433
-     * @throws \EE_Error
434
-     */
435
-    public function get_active_events($query_params, $count = false)
436
-    {
437
-        if (array_key_exists(0, $query_params)) {
438
-            $where_params = $query_params[0];
439
-            unset($query_params[0]);
440
-        } else {
441
-            $where_params = array();
442
-        }
443
-        // if we have count make sure we don't include group by
444
-        if ($count && isset($query_params['group_by'])) {
445
-            unset($query_params['group_by']);
446
-        }
447
-        // let's add specific query_params for active_events
448
-        // keep in mind this will override any sent status in the query AND any date queries.
449
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
450
-        //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
451
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
452
-            $where_params['Datetime.DTT_EVT_start******'] = array(
453
-                '<',
454
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
455
-            );
456
-        } else {
457
-            $where_params['Datetime.DTT_EVT_start'] = array(
458
-                '<',
459
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
460
-            );
461
-        }
462
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
463
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
464
-                '>',
465
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
466
-            );
467
-        } else {
468
-            $where_params['Datetime.DTT_EVT_end'] = array(
469
-                '>',
470
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
471
-            );
472
-        }
473
-        $query_params[0] = $where_params;
474
-        // don't use $query_params with count()
475
-        // because we don't want to include additional query clauses like "GROUP BY"
476
-        return $count
477
-            ? $this->count(array($where_params), 'EVT_ID', true)
478
-            : $this->get_all($query_params);
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * get all events that are published and have an event start time later than now
485
-     *
486
-     * @param  array $query_params An array of query params to further filter on
487
-     *                             (Note that status and DTT_EVT_start will be overridden)
488
-     * @param bool   $count        whether to return the count or not (default FALSE)
489
-     * @return EE_Event[]|int
490
-     * @throws \EE_Error
491
-     */
492
-    public function get_upcoming_events($query_params, $count = false)
493
-    {
494
-        if (array_key_exists(0, $query_params)) {
495
-            $where_params = $query_params[0];
496
-            unset($query_params[0]);
497
-        } else {
498
-            $where_params = array();
499
-        }
500
-        // if we have count make sure we don't include group by
501
-        if ($count && isset($query_params['group_by'])) {
502
-            unset($query_params['group_by']);
503
-        }
504
-        // let's add specific query_params for active_events
505
-        // keep in mind this will override any sent status in the query AND any date queries.
506
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
507
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
508
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
509
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
510
-                '>',
511
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
512
-            );
513
-        } else {
514
-            $where_params['Datetime.DTT_EVT_start'] = array(
515
-                '>',
516
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
517
-            );
518
-        }
519
-        $query_params[0] = $where_params;
520
-        // don't use $query_params with count()
521
-        // because we don't want to include additional query clauses like "GROUP BY"
522
-        return $count
523
-            ? $this->count(array($where_params), 'EVT_ID', true)
524
-            : $this->get_all($query_params);
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * Gets all events that are published
531
-     * and have an event end time later than now
532
-     *
533
-     * @param  array $query_params An array of query params to further filter on
534
-     *                             (note that status and DTT_EVT_end will be overridden)
535
-     * @param bool   $count        whether to return the count or not (default FALSE)
536
-     * @return EE_Event[]|int
537
-     * @throws \EE_Error
538
-     */
539
-    public function get_active_and_upcoming_events($query_params, $count = false)
540
-    {
541
-        if (array_key_exists(0, $query_params)) {
542
-            $where_params = $query_params[0];
543
-            unset($query_params[0]);
544
-        } else {
545
-            $where_params = array();
546
-        }
547
-        // if we have count make sure we don't include group by
548
-        if ($count && isset($query_params['group_by'])) {
549
-            unset($query_params['group_by']);
550
-        }
551
-        // let's add specific query_params for active_events
552
-        // keep in mind this will override any sent status in the query AND any date queries.
553
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
554
-        // add where params for DTT_EVT_end
555
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
556
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
557
-                '>',
558
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
559
-            );
560
-        } else {
561
-            $where_params['Datetime.DTT_EVT_end'] = array(
562
-                '>',
563
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
564
-            );
565
-        }
566
-        $query_params[0] = $where_params;
567
-        // don't use $query_params with count()
568
-        // because we don't want to include additional query clauses like "GROUP BY"
569
-        return $count
570
-            ? $this->count(array($where_params), 'EVT_ID', true)
571
-            : $this->get_all($query_params);
572
-    }
573
-
574
-
575
-
576
-    /**
577
-     * This only returns events that are expired.
578
-     * They may still be published but all their datetimes have expired.
579
-     *
580
-     * @param  array $query_params An array of query params to further filter on
581
-     *                             (note that status and DTT_EVT_end will be overridden)
582
-     * @param bool   $count        whether to return the count or not (default FALSE)
583
-     * @return EE_Event[]|int
584
-     * @throws \EE_Error
585
-     */
586
-    public function get_expired_events($query_params, $count = false)
587
-    {
588
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
589
-        // if we have count make sure we don't include group by
590
-        if ($count && isset($query_params['group_by'])) {
591
-            unset($query_params['group_by']);
592
-        }
593
-        // let's add specific query_params for active_events
594
-        // keep in mind this will override any sent status in the query AND any date queries.
595
-        if (isset($where_params['status'])) {
596
-            unset($where_params['status']);
597
-        }
598
-        $exclude_query = $query_params;
599
-        if (isset($exclude_query[0])) {
600
-            unset($exclude_query[0]);
601
-        }
602
-        $exclude_query[0] = array(
603
-            'Datetime.DTT_EVT_end' => array(
604
-                '>',
605
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
606
-            ),
607
-        );
608
-        // first get all events that have datetimes where its not expired.
609
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
610
-        $event_ids = array_keys($event_ids);
611
-        // if we have any additional query_params, let's add them to the 'AND' condition
612
-        $and_condition = array(
613
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
614
-            'EVT_ID'               => array('NOT IN', $event_ids),
615
-        );
616
-        if (isset($where_params['OR'])) {
617
-            $and_condition['OR'] = $where_params['OR'];
618
-            unset($where_params['OR']);
619
-        }
620
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
621
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
622
-            unset($where_params['Datetime.DTT_EVT_end']);
623
-        }
624
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
625
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
626
-            unset($where_params['Datetime.DTT_EVT_start']);
627
-        }
628
-        // merge remaining $where params with the and conditions.
629
-        $where_params['AND'] = array_merge($and_condition, $where_params);
630
-        $query_params[0] = $where_params;
631
-        // don't use $query_params with count()
632
-        // because we don't want to include additional query clauses like "GROUP BY"
633
-        return $count
634
-            ? $this->count(array($where_params), 'EVT_ID', true)
635
-            : $this->get_all($query_params);
636
-    }
637
-
638
-
639
-
640
-    /**
641
-     * This basically just returns the events that do not have the publish status.
642
-     *
643
-     * @param  array   $query_params An array of query params to further filter on
644
-     *                               (note that status will be overwritten)
645
-     * @param  boolean $count        whether to return the count or not (default FALSE)
646
-     * @return EE_Event[]|int
647
-     * @throws \EE_Error
648
-     */
649
-    public function get_inactive_events($query_params, $count = false)
650
-    {
651
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
652
-        // let's add in specific query_params for inactive events.
653
-        if (isset($where_params['status'])) {
654
-            unset($where_params['status']);
655
-        }
656
-        // if we have count make sure we don't include group by
657
-        if ($count && isset($query_params['group_by'])) {
658
-            unset($query_params['group_by']);
659
-        }
660
-        // if we have any additional query_params, let's add them to the 'AND' condition
661
-        $where_params['AND']['status'] = array('!=', 'publish');
662
-        if (isset($where_params['OR'])) {
663
-            $where_params['AND']['OR'] = $where_params['OR'];
664
-            unset($where_params['OR']);
665
-        }
666
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
667
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
668
-            unset($where_params['Datetime.DTT_EVT_end']);
669
-        }
670
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
671
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
672
-            unset($where_params['Datetime.DTT_EVT_start']);
673
-        }
674
-        $query_params[0] = $where_params;
675
-        // don't use $query_params with count()
676
-        // because we don't want to include additional query clauses like "GROUP BY"
677
-        return $count
678
-            ? $this->count(array($where_params), 'EVT_ID', true)
679
-            : $this->get_all($query_params);
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
686
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
687
-     * attached to the event. See parent for param descriptions
688
-     *
689
-     * @param        $id_or_obj
690
-     * @param        $other_model_id_or_obj
691
-     * @param string $relationName
692
-     * @param array  $where_query
693
-     * @return EE_Base_Class
694
-     * @throws EE_Error
695
-     */
696
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
697
-    {
698
-        if ($relationName === 'Price') {
699
-            //let's get the PRC object for the given ID to make sure that we aren't dealing with a default
700
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
701
-            //if EVT_ID = 0, then this is a default
702
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
703
-                //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
704
-                $prc_chk->set('PRC_ID', 0);
705
-            }
706
-            //run parent
707
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
708
-        }
709
-        //otherwise carry on as normal
710
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
711
-    }
712
-
713
-
714
-
715
-    /******************** DEPRECATED METHODS ********************/
716
-
717
-
718
-
719
-    /**
720
-     * _get_question_target_db_column
721
-     *
722
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
723
-     *             EE_Registration_Custom_Questions_Form located in
724
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
725
-     * @access     public
726
-     * @param    EE_Registration $registration (so existing answers for registration are included)
727
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
728
-     *                                         registration).
729
-     * @throws EE_Error
730
-     * @return    array
731
-     */
732
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
733
-    {
734
-        if (empty($EVT_ID)) {
735
-            throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
736
-                'event_espresso'));
737
-        }
738
-        $questions = array();
739
-        // get all question groups for event
740
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
741
-        if (! empty($qgs)) {
742
-            foreach ($qgs as $qg) {
743
-                $qsts = $qg->questions();
744
-                $questions[$qg->ID()] = $qg->model_field_array();
745
-                $questions[$qg->ID()]['QSG_questions'] = array();
746
-                foreach ($qsts as $qst) {
747
-                    if ($qst->is_system_question()) {
748
-                        continue;
749
-                    }
750
-                    $answer = EEM_Answer::instance()->get_one(array(
751
-                        array(
752
-                            'QST_ID' => $qst->ID(),
753
-                            'REG_ID' => $registration->ID(),
754
-                        ),
755
-                    ));
756
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
757
-                    $qst_name = $qstn_id = $qst->ID();
758
-                    $ans_id = $answer->ID();
759
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
760
-                    $input_name = '';
761
-                    $input_id = sanitize_key($qst->display_text());
762
-                    $input_class = '';
763
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
764
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
765
-                                                                                           . $input_name
766
-                                                                                           . $qst_name;
767
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
768
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
769
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
770
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
771
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
772
-                    //leave responses as-is, don't convert stuff into html entities please!
773
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
774
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
775
-                        $QSOs = $qst->options(true, $answer->value());
776
-                        if (is_array($QSOs)) {
777
-                            foreach ($QSOs as $QSO_ID => $QSO) {
778
-                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
779
-                            }
780
-                        }
781
-                    }
782
-                }
783
-            }
784
-        }
785
-        return $questions;
786
-    }
21
+	/**
22
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
23
+	 * event
24
+	 */
25
+	const sold_out = 'sold_out';
26
+
27
+	/**
28
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
29
+	 * date)
30
+	 */
31
+	const postponed = 'postponed';
32
+
33
+	/**
34
+	 * constant used by status(), indicating that the event will no longer occur
35
+	 */
36
+	const cancelled = 'cancelled';
37
+
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected static $_default_reg_status;
43
+
44
+
45
+	/**
46
+	 * This is the default for the additional limit field.
47
+	 * @var int
48
+	 */
49
+	protected static $_default_additional_limit = 10;
50
+
51
+
52
+	/**
53
+	 * private instance of the Event object
54
+	 *
55
+	 * @var EEM_Event
56
+	 */
57
+	protected static $_instance;
58
+
59
+
60
+
61
+
62
+	/**
63
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
64
+	 *
65
+	 * @param string $timezone
66
+	 * @throws \EE_Error
67
+	 */
68
+	protected function __construct($timezone = null)
69
+	{
70
+		EE_Registry::instance()->load_model('Registration');
71
+		$this->singular_item = esc_html__('Event', 'event_espresso');
72
+		$this->plural_item = esc_html__('Events', 'event_espresso');
73
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
74
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
75
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
76
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
77
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
78
+		//	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
79
+		$this->_custom_stati = apply_filters(
80
+			'AFEE__EEM_Event__construct___custom_stati',
81
+			array(
82
+				EEM_Event::cancelled => array(
83
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
84
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
85
+				),
86
+				EEM_Event::postponed => array(
87
+					'label'  => esc_html__('Postponed', 'event_espresso'),
88
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
89
+				),
90
+				EEM_Event::sold_out  => array(
91
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
92
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
93
+				),
94
+			)
95
+		);
96
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
97
+			: self::$_default_reg_status;
98
+		$this->_tables = array(
99
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
100
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
101
+		);
102
+		$this->_fields = array(
103
+			'Event_CPT'  => array(
104
+				'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
105
+					esc_html__('Post ID for Event', 'event_espresso')),
106
+				'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
107
+					false,
108
+					''),
109
+				'EVT_desc'       => new EE_Post_Content_Field('post_content',
110
+					esc_html__('Event Description', 'event_espresso'),
111
+					false, ''),
112
+				'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
113
+					''),
114
+				'EVT_created'    => new EE_Datetime_Field('post_date',
115
+					esc_html__('Date/Time Event Created', 'event_espresso'),
116
+					false, EE_Datetime_Field::now),
117
+				'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
118
+					esc_html__('Event Short Description', 'event_espresso'), false, ''),
119
+				'EVT_modified'   => new EE_Datetime_Field('post_modified',
120
+					esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
121
+				'EVT_wp_user'    => new EE_WP_User_Field('post_author',
122
+					esc_html__('Event Creator ID', 'event_espresso'),
123
+					false),
124
+				'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
125
+					false,
126
+					0),
127
+				'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
128
+					false,
129
+					1),
130
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
131
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
132
+				'status'         => new EE_WP_Post_Status_Field('post_status',
133
+					esc_html__('Event Status', 'event_espresso'),
134
+					false, 'draft', $this->_custom_stati),
135
+			),
136
+			'Event_Meta' => array(
137
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
138
+					esc_html__('Event Meta Row ID', 'event_espresso'), false),
139
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
140
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
141
+				'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
142
+					esc_html__('Display Description Flag', 'event_espresso'), false, 1),
143
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
144
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
145
+				'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
146
+					esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
147
+				'EVT_additional_limit'            => new EE_Integer_Field(
148
+					'EVT_additional_limit',
149
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
150
+					true,
151
+					self::$_default_additional_limit
152
+				),
153
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
154
+					'EVT_default_registration_status',
155
+					esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
156
+					EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
157
+				),
158
+				'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
159
+					esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
160
+				'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
161
+					esc_html__('Event Phone Number', 'event_espresso'), false),
162
+				'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
163
+					esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
164
+				'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
165
+					esc_html__('Timezone (name) for Event times', 'event_espresso'), false),
166
+				'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
167
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
168
+				'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
169
+					esc_html__('Accept Donations?', 'event_espresso'), false, false),
170
+			),
171
+		);
172
+		$this->_model_relations = array(
173
+			'Registration'           => new EE_Has_Many_Relation(),
174
+			'Datetime'               => new EE_Has_Many_Relation(),
175
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
176
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
177
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
178
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
179
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
180
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
181
+			'WP_User'                => new EE_Belongs_To_Relation(),
182
+		);
183
+		//this model is generally available for reading
184
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
185
+		parent::__construct($timezone);
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * @param string $default_reg_status
192
+	 */
193
+	public static function set_default_reg_status($default_reg_status)
194
+	{
195
+		self::$_default_reg_status = $default_reg_status;
196
+		// if EEM_Event has already been instantiated,
197
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
198
+		if (self::$_instance instanceof EEM_Event) {
199
+			$default_reg_status = new EE_Enum_Text_Field(
200
+				'EVT_default_registration_status',
201
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
202
+				false,
203
+				$default_reg_status,
204
+				EEM_Registration::reg_status_array()
205
+			);
206
+			$default_reg_status->_construct_finalize(
207
+				'Event_Meta',
208
+				'EVT_default_registration_status',
209
+				'EEM_Event'
210
+			);
211
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * Used to override the default for the additional limit field.
218
+	 * @param $additional_limit
219
+	 */
220
+	public static function set_default_additional_limit($additional_limit)
221
+	{
222
+		self::$_default_additional_limit = (int) $additional_limit;
223
+		if (self::$_instance instanceof EEM_Event) {
224
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
225
+				'EVT_additional_limit',
226
+				__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
227
+				true,
228
+				self::$_default_additional_limit
229
+			);
230
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
231
+				'Event_Meta',
232
+				'EVT_additional_limit',
233
+				'EEM_Event'
234
+			);
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * Return what is currently set as the default additional limit for the event.
241
+	 * @return int
242
+	 */
243
+	public static function get_default_additional_limit()
244
+	{
245
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
246
+	}
247
+
248
+
249
+	/**
250
+	 * get_question_groups
251
+	 *
252
+	 * @return array
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function get_all_question_groups()
256
+	{
257
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
258
+			array(
259
+				array('QSG_deleted' => false),
260
+				'order_by' => array('QSG_order' => 'ASC'),
261
+			)
262
+		);
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * get_question_groups
269
+	 *
270
+	 * @param int $EVT_ID
271
+	 * @return array|bool
272
+	 * @throws \EE_Error
273
+	 */
274
+	public function get_all_event_question_groups($EVT_ID = 0)
275
+	{
276
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
277
+			EE_Error::add_error(
278
+				esc_html__(
279
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
280
+					'event_espresso'
281
+				),
282
+				__FILE__, __FUNCTION__, __LINE__
283
+			);
284
+			return false;
285
+		}
286
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
287
+			array(
288
+				array('EVT_ID' => $EVT_ID),
289
+			)
290
+		);
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * get_question_groups
297
+	 *
298
+	 * @param int     $EVT_ID
299
+	 * @param boolean $for_primary_attendee
300
+	 * @return array|bool
301
+	 * @throws \EE_Error
302
+	 */
303
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
304
+	{
305
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
306
+			EE_Error::add_error(
307
+				esc_html__(
308
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
309
+					'event_espresso'
310
+				),
311
+				__FILE__, __FUNCTION__, __LINE__
312
+			);
313
+			return false;
314
+		}
315
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
316
+			array(
317
+				array(
318
+					'EVT_ID'      => $EVT_ID,
319
+					'EQG_primary' => $for_primary_attendee,
320
+				),
321
+			)
322
+		);
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * get_question_groups
329
+	 *
330
+	 * @param int             $EVT_ID
331
+	 * @param EE_Registration $registration
332
+	 * @return array|bool
333
+	 * @throws \EE_Error
334
+	 */
335
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
336
+	{
337
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
338
+			EE_Error::add_error(
339
+				esc_html__(
340
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
341
+					'event_espresso'
342
+				),
343
+				__FILE__, __FUNCTION__, __LINE__
344
+			);
345
+			return false;
346
+		}
347
+		$where_params = array(
348
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
349
+			'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
350
+			'QSG_deleted'                      => false,
351
+		);
352
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
353
+			array(
354
+				$where_params,
355
+				'order_by' => array('QSG_order' => 'ASC'),
356
+			)
357
+		);
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * get_question_target_db_column
364
+	 *
365
+	 * @param string $QSG_IDs csv list of $QSG IDs
366
+	 * @return array|bool
367
+	 * @throws \EE_Error
368
+	 */
369
+	public function get_questions_in_groups($QSG_IDs = '')
370
+	{
371
+		if (empty($QSG_IDs)) {
372
+			EE_Error::add_error(
373
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
374
+				__FILE__, __FUNCTION__, __LINE__
375
+			);
376
+			return false;
377
+		}
378
+		return EE_Registry::instance()->load_model('Question')->get_all(
379
+			array(
380
+				array(
381
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
382
+					'QST_deleted'           => false,
383
+					'QST_admin_only'        => is_admin(),
384
+				),
385
+				'order_by' => 'QST_order',
386
+			)
387
+		);
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * get_options_for_question
394
+	 *
395
+	 * @param string $QST_IDs csv list of $QST IDs
396
+	 * @return array|bool
397
+	 * @throws \EE_Error
398
+	 */
399
+	public function get_options_for_question($QST_IDs)
400
+	{
401
+		if (empty($QST_IDs)) {
402
+			EE_Error::add_error(
403
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
404
+				__FILE__, __FUNCTION__, __LINE__
405
+			);
406
+			return false;
407
+		}
408
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
409
+			array(
410
+				array(
411
+					'Question.QST_ID' => array('IN', $QST_IDs),
412
+					'QSO_deleted'     => false,
413
+				),
414
+				'order_by' => 'QSO_ID',
415
+			)
416
+		);
417
+	}
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+	/**
426
+	 * Gets all events that are published
427
+	 * and have event start time earlier than now and an event end time later than now
428
+	 *
429
+	 * @param  array $query_params An array of query params to further filter on
430
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
431
+	 * @param bool   $count        whether to return the count or not (default FALSE)
432
+	 * @return EE_Event[]|int
433
+	 * @throws \EE_Error
434
+	 */
435
+	public function get_active_events($query_params, $count = false)
436
+	{
437
+		if (array_key_exists(0, $query_params)) {
438
+			$where_params = $query_params[0];
439
+			unset($query_params[0]);
440
+		} else {
441
+			$where_params = array();
442
+		}
443
+		// if we have count make sure we don't include group by
444
+		if ($count && isset($query_params['group_by'])) {
445
+			unset($query_params['group_by']);
446
+		}
447
+		// let's add specific query_params for active_events
448
+		// keep in mind this will override any sent status in the query AND any date queries.
449
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
450
+		//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
451
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
452
+			$where_params['Datetime.DTT_EVT_start******'] = array(
453
+				'<',
454
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
455
+			);
456
+		} else {
457
+			$where_params['Datetime.DTT_EVT_start'] = array(
458
+				'<',
459
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
460
+			);
461
+		}
462
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
463
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
464
+				'>',
465
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
466
+			);
467
+		} else {
468
+			$where_params['Datetime.DTT_EVT_end'] = array(
469
+				'>',
470
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
471
+			);
472
+		}
473
+		$query_params[0] = $where_params;
474
+		// don't use $query_params with count()
475
+		// because we don't want to include additional query clauses like "GROUP BY"
476
+		return $count
477
+			? $this->count(array($where_params), 'EVT_ID', true)
478
+			: $this->get_all($query_params);
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * get all events that are published and have an event start time later than now
485
+	 *
486
+	 * @param  array $query_params An array of query params to further filter on
487
+	 *                             (Note that status and DTT_EVT_start will be overridden)
488
+	 * @param bool   $count        whether to return the count or not (default FALSE)
489
+	 * @return EE_Event[]|int
490
+	 * @throws \EE_Error
491
+	 */
492
+	public function get_upcoming_events($query_params, $count = false)
493
+	{
494
+		if (array_key_exists(0, $query_params)) {
495
+			$where_params = $query_params[0];
496
+			unset($query_params[0]);
497
+		} else {
498
+			$where_params = array();
499
+		}
500
+		// if we have count make sure we don't include group by
501
+		if ($count && isset($query_params['group_by'])) {
502
+			unset($query_params['group_by']);
503
+		}
504
+		// let's add specific query_params for active_events
505
+		// keep in mind this will override any sent status in the query AND any date queries.
506
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
507
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
508
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
509
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
510
+				'>',
511
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
512
+			);
513
+		} else {
514
+			$where_params['Datetime.DTT_EVT_start'] = array(
515
+				'>',
516
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
517
+			);
518
+		}
519
+		$query_params[0] = $where_params;
520
+		// don't use $query_params with count()
521
+		// because we don't want to include additional query clauses like "GROUP BY"
522
+		return $count
523
+			? $this->count(array($where_params), 'EVT_ID', true)
524
+			: $this->get_all($query_params);
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * Gets all events that are published
531
+	 * and have an event end time later than now
532
+	 *
533
+	 * @param  array $query_params An array of query params to further filter on
534
+	 *                             (note that status and DTT_EVT_end will be overridden)
535
+	 * @param bool   $count        whether to return the count or not (default FALSE)
536
+	 * @return EE_Event[]|int
537
+	 * @throws \EE_Error
538
+	 */
539
+	public function get_active_and_upcoming_events($query_params, $count = false)
540
+	{
541
+		if (array_key_exists(0, $query_params)) {
542
+			$where_params = $query_params[0];
543
+			unset($query_params[0]);
544
+		} else {
545
+			$where_params = array();
546
+		}
547
+		// if we have count make sure we don't include group by
548
+		if ($count && isset($query_params['group_by'])) {
549
+			unset($query_params['group_by']);
550
+		}
551
+		// let's add specific query_params for active_events
552
+		// keep in mind this will override any sent status in the query AND any date queries.
553
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
554
+		// add where params for DTT_EVT_end
555
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
556
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
557
+				'>',
558
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
559
+			);
560
+		} else {
561
+			$where_params['Datetime.DTT_EVT_end'] = array(
562
+				'>',
563
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
564
+			);
565
+		}
566
+		$query_params[0] = $where_params;
567
+		// don't use $query_params with count()
568
+		// because we don't want to include additional query clauses like "GROUP BY"
569
+		return $count
570
+			? $this->count(array($where_params), 'EVT_ID', true)
571
+			: $this->get_all($query_params);
572
+	}
573
+
574
+
575
+
576
+	/**
577
+	 * This only returns events that are expired.
578
+	 * They may still be published but all their datetimes have expired.
579
+	 *
580
+	 * @param  array $query_params An array of query params to further filter on
581
+	 *                             (note that status and DTT_EVT_end will be overridden)
582
+	 * @param bool   $count        whether to return the count or not (default FALSE)
583
+	 * @return EE_Event[]|int
584
+	 * @throws \EE_Error
585
+	 */
586
+	public function get_expired_events($query_params, $count = false)
587
+	{
588
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
589
+		// if we have count make sure we don't include group by
590
+		if ($count && isset($query_params['group_by'])) {
591
+			unset($query_params['group_by']);
592
+		}
593
+		// let's add specific query_params for active_events
594
+		// keep in mind this will override any sent status in the query AND any date queries.
595
+		if (isset($where_params['status'])) {
596
+			unset($where_params['status']);
597
+		}
598
+		$exclude_query = $query_params;
599
+		if (isset($exclude_query[0])) {
600
+			unset($exclude_query[0]);
601
+		}
602
+		$exclude_query[0] = array(
603
+			'Datetime.DTT_EVT_end' => array(
604
+				'>',
605
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
606
+			),
607
+		);
608
+		// first get all events that have datetimes where its not expired.
609
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
610
+		$event_ids = array_keys($event_ids);
611
+		// if we have any additional query_params, let's add them to the 'AND' condition
612
+		$and_condition = array(
613
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
614
+			'EVT_ID'               => array('NOT IN', $event_ids),
615
+		);
616
+		if (isset($where_params['OR'])) {
617
+			$and_condition['OR'] = $where_params['OR'];
618
+			unset($where_params['OR']);
619
+		}
620
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
621
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
622
+			unset($where_params['Datetime.DTT_EVT_end']);
623
+		}
624
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
625
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
626
+			unset($where_params['Datetime.DTT_EVT_start']);
627
+		}
628
+		// merge remaining $where params with the and conditions.
629
+		$where_params['AND'] = array_merge($and_condition, $where_params);
630
+		$query_params[0] = $where_params;
631
+		// don't use $query_params with count()
632
+		// because we don't want to include additional query clauses like "GROUP BY"
633
+		return $count
634
+			? $this->count(array($where_params), 'EVT_ID', true)
635
+			: $this->get_all($query_params);
636
+	}
637
+
638
+
639
+
640
+	/**
641
+	 * This basically just returns the events that do not have the publish status.
642
+	 *
643
+	 * @param  array   $query_params An array of query params to further filter on
644
+	 *                               (note that status will be overwritten)
645
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
646
+	 * @return EE_Event[]|int
647
+	 * @throws \EE_Error
648
+	 */
649
+	public function get_inactive_events($query_params, $count = false)
650
+	{
651
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
652
+		// let's add in specific query_params for inactive events.
653
+		if (isset($where_params['status'])) {
654
+			unset($where_params['status']);
655
+		}
656
+		// if we have count make sure we don't include group by
657
+		if ($count && isset($query_params['group_by'])) {
658
+			unset($query_params['group_by']);
659
+		}
660
+		// if we have any additional query_params, let's add them to the 'AND' condition
661
+		$where_params['AND']['status'] = array('!=', 'publish');
662
+		if (isset($where_params['OR'])) {
663
+			$where_params['AND']['OR'] = $where_params['OR'];
664
+			unset($where_params['OR']);
665
+		}
666
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
667
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
668
+			unset($where_params['Datetime.DTT_EVT_end']);
669
+		}
670
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
671
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
672
+			unset($where_params['Datetime.DTT_EVT_start']);
673
+		}
674
+		$query_params[0] = $where_params;
675
+		// don't use $query_params with count()
676
+		// because we don't want to include additional query clauses like "GROUP BY"
677
+		return $count
678
+			? $this->count(array($where_params), 'EVT_ID', true)
679
+			: $this->get_all($query_params);
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
686
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
687
+	 * attached to the event. See parent for param descriptions
688
+	 *
689
+	 * @param        $id_or_obj
690
+	 * @param        $other_model_id_or_obj
691
+	 * @param string $relationName
692
+	 * @param array  $where_query
693
+	 * @return EE_Base_Class
694
+	 * @throws EE_Error
695
+	 */
696
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
697
+	{
698
+		if ($relationName === 'Price') {
699
+			//let's get the PRC object for the given ID to make sure that we aren't dealing with a default
700
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
701
+			//if EVT_ID = 0, then this is a default
702
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
703
+				//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
704
+				$prc_chk->set('PRC_ID', 0);
705
+			}
706
+			//run parent
707
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
708
+		}
709
+		//otherwise carry on as normal
710
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
711
+	}
712
+
713
+
714
+
715
+	/******************** DEPRECATED METHODS ********************/
716
+
717
+
718
+
719
+	/**
720
+	 * _get_question_target_db_column
721
+	 *
722
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
723
+	 *             EE_Registration_Custom_Questions_Form located in
724
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
725
+	 * @access     public
726
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
727
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
728
+	 *                                         registration).
729
+	 * @throws EE_Error
730
+	 * @return    array
731
+	 */
732
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
733
+	{
734
+		if (empty($EVT_ID)) {
735
+			throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
736
+				'event_espresso'));
737
+		}
738
+		$questions = array();
739
+		// get all question groups for event
740
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
741
+		if (! empty($qgs)) {
742
+			foreach ($qgs as $qg) {
743
+				$qsts = $qg->questions();
744
+				$questions[$qg->ID()] = $qg->model_field_array();
745
+				$questions[$qg->ID()]['QSG_questions'] = array();
746
+				foreach ($qsts as $qst) {
747
+					if ($qst->is_system_question()) {
748
+						continue;
749
+					}
750
+					$answer = EEM_Answer::instance()->get_one(array(
751
+						array(
752
+							'QST_ID' => $qst->ID(),
753
+							'REG_ID' => $registration->ID(),
754
+						),
755
+					));
756
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
757
+					$qst_name = $qstn_id = $qst->ID();
758
+					$ans_id = $answer->ID();
759
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
760
+					$input_name = '';
761
+					$input_id = sanitize_key($qst->display_text());
762
+					$input_class = '';
763
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
764
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
765
+																						   . $input_name
766
+																						   . $qst_name;
767
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
768
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
769
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
770
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
771
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
772
+					//leave responses as-is, don't convert stuff into html entities please!
773
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
774
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
775
+						$QSOs = $qst->options(true, $answer->value());
776
+						if (is_array($QSOs)) {
777
+							foreach ($QSOs as $QSO_ID => $QSO) {
778
+								$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
779
+							}
780
+						}
781
+					}
782
+				}
783
+			}
784
+		}
785
+		return $questions;
786
+	}
787 787
 
788 788
 
789 789
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\orm\ModelFieldFactory;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6
-require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
6
+require_once(EE_MODELS.'EEM_CPT_Base.model.php');
7 7
 
8 8
 
9 9
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      */
274 274
     public function get_all_event_question_groups($EVT_ID = 0)
275 275
     {
276
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
276
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
277 277
             EE_Error::add_error(
278 278
                 esc_html__(
279 279
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      */
303 303
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
304 304
     {
305
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
305
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
306 306
             EE_Error::add_error(
307 307
                 esc_html__(
308 308
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
      */
335 335
     public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
336 336
     {
337
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
337
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
338 338
             EE_Error::add_error(
339 339
                 esc_html__(
340 340
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
         $questions = array();
739 739
         // get all question groups for event
740 740
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
741
-        if (! empty($qgs)) {
741
+        if ( ! empty($qgs)) {
742 742
             foreach ($qgs as $qg) {
743 743
                 $qsts = $qg->questions();
744 744
                 $questions[$qg->ID()] = $qg->model_field_array();
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
757 757
                     $qst_name = $qstn_id = $qst->ID();
758 758
                     $ans_id = $answer->ID();
759
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
759
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
760 760
                     $input_name = '';
761 761
                     $input_id = sanitize_key($qst->display_text());
762 762
                     $input_class = '';
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
765 765
                                                                                            . $input_name
766 766
                                                                                            . $qst_name;
767
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
767
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
768 768
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
769 769
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
770 770
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
Please login to merge, or discard this patch.
core/services/orm/ModelFieldFactory.php 3 patches
Doc Comments   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -132,7 +132,6 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * @param string $table_column
134 134
      * @param string $nice_name
135
-     * @param string $timezone_string
136 135
      * @param bool   $nullable
137 136
      * @param string $default_value
138 137
      * @throws EE_Error
@@ -179,7 +178,7 @@  discard block
 block discarded – undo
179 178
      * @param string $table_column
180 179
      * @param string $nice_name
181 180
      * @param bool   $nullable
182
-     * @param null   $default_value
181
+     * @param integer   $default_value
183 182
      * @return EE_DB_Only_Int_Field
184 183
      */
185 184
     public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null)
@@ -295,7 +294,7 @@  discard block
 block discarded – undo
295 294
      * @param string $table_column
296 295
      * @param string $nice_name
297 296
      * @param bool   $nullable
298
-     * @param null   $default_value
297
+     * @param integer   $default_value
299 298
      * @param string $model_name
300 299
      * @return EE_Foreign_Key_Int_Field
301 300
      */
@@ -313,7 +312,7 @@  discard block
 block discarded – undo
313 312
      * @param string $table_column
314 313
      * @param string $nice_name
315 314
      * @param bool   $nullable
316
-     * @param null   $default_value
315
+     * @param string   $default_value
317 316
      * @param string $model_name
318 317
      * @return EE_Foreign_Key_String_Field
319 318
      */
@@ -564,7 +563,7 @@  discard block
 block discarded – undo
564 563
      * @param string $table_column
565 564
      * @param string $nice_name
566 565
      * @param bool   $nullable
567
-     * @param mixed  $default_value
566
+     * @param string  $default_value
568 567
      * @param array  $values        If additional stati are to be used other than the default WP statuses,
569 568
      *                              then they can be registered via this property.
570 569
      *                              The format of the array should be as follows:
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -33,9 +33,6 @@
 block discarded – undo
33 33
 use EE_WP_Post_Status_Field;
34 34
 use EE_WP_Post_Type_Field;
35 35
 use EE_WP_User_Field;
36
-use EventEspresso\core\exceptions\InvalidDataTypeException;
37
-use EventEspresso\core\exceptions\InvalidInterfaceException;
38
-use EventEspresso\core\services\loaders\LoaderFactory;
39 36
 use EventEspresso\core\services\loaders\LoaderInterface;
40 37
 use InvalidArgumentException;
41 38
 
Please login to merge, or discard this patch.
Indentation   +570 added lines, -570 removed lines patch added patch discarded remove patch
@@ -53,576 +53,576 @@
 block discarded – undo
53 53
 class ModelFieldFactory
54 54
 {
55 55
 
56
-    /**
57
-     * @var LoaderInterface $loader
58
-     */
59
-    private $loader;
60
-
61
-
62
-
63
-    /**
64
-     * ModelFieldFactory constructor.
65
-     *
66
-     * @param LoaderInterface $loader
67
-     */
68
-    public function __construct(LoaderInterface $loader)
69
-    {
70
-        $this->loader = $loader;
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     * @param string $table_column
77
-     * @param string $nice_name
78
-     * @param bool   $nullable
79
-     * @param null   $default_value
80
-     * @return EE_All_Caps_Text_Field
81
-     */
82
-    public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null)
83
-    {
84
-        return $this->loader->getNew(
85
-            'EE_All_Caps_Text_Field',
86
-            array($table_column, $nice_name, $nullable, $default_value)
87
-        );
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * @param string $table_column
94
-     * @param string $nice_name
95
-     * @param bool   $nullable
96
-     * @param null   $default_value
97
-     * @param string $model_name
98
-     * @return EE_Any_Foreign_Model_Name_Field
99
-     */
100
-    public function createAnyForeignModelNameField(
101
-        $table_column,
102
-        $nice_name,
103
-        $nullable,
104
-        $default_value = null,
105
-        $model_name
106
-    ) {
107
-        return $this->loader->getNew(
108
-            'EE_Any_Foreign_Model_Name_Field',
109
-            array($table_column, $nice_name, $nullable, $default_value, $model_name)
110
-        );
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param string $table_column
117
-     * @param string $nice_name
118
-     * @param bool   $nullable
119
-     * @param null   $default_value
120
-     * @return EE_Boolean_Field
121
-     */
122
-    public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null)
123
-    {
124
-        return $this->loader->getNew(
125
-            'EE_Boolean_Field',
126
-            array($table_column, $nice_name, $nullable, $default_value)
127
-        );
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @param string $table_column
134
-     * @param string $nice_name
135
-     * @param string $timezone_string
136
-     * @param bool   $nullable
137
-     * @param string $default_value
138
-     * @throws EE_Error
139
-     * @throws InvalidArgumentException
140
-     * @return EE_Datetime_Field
141
-     */
142
-    public function createDatetimeField(
143
-        $table_column,
144
-        $nice_name,
145
-        $nullable = false,
146
-        $default_value = EE_Datetime_Field::now
147
-    ) {
148
-        return $this->loader->getNew(
149
-            'EE_Datetime_Field',
150
-            array(
151
-                $table_column,
152
-                $nice_name,
153
-                $nullable,
154
-                $default_value
155
-            )
156
-        );
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * @param string $table_column
163
-     * @param string $nice_name
164
-     * @param bool   $nullable
165
-     * @param null   $default_value
166
-     * @return EE_DB_Only_Float_Field
167
-     */
168
-    public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null)
169
-    {
170
-        return $this->loader->getNew(
171
-            'EE_DB_Only_Float_Field',
172
-            array($table_column, $nice_name, $nullable, $default_value)
173
-        );
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * @param string $table_column
180
-     * @param string $nice_name
181
-     * @param bool   $nullable
182
-     * @param null   $default_value
183
-     * @return EE_DB_Only_Int_Field
184
-     */
185
-    public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null)
186
-    {
187
-        return $this->loader->getNew(
188
-            'EE_DB_Only_Int_Field',
189
-            array($table_column, $nice_name, $nullable, $default_value)
190
-        );
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * @param string $table_column
197
-     * @param string $nice_name
198
-     * @param bool   $nullable
199
-     * @param null   $default_value
200
-     * @return EE_DB_Only_Text_Field
201
-     */
202
-    public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null)
203
-    {
204
-        return $this->loader->getNew(
205
-            'EE_DB_Only_Text_Field',
206
-            array($table_column, $nice_name, $nullable, $default_value)
207
-        );
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * @param string $table_column
214
-     * @param string $nice_name
215
-     * @param bool   $nullable
216
-     * @param string $default_value
217
-     * @return EE_Email_Field
218
-     */
219
-    public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '')
220
-    {
221
-        return $this->loader->getNew(
222
-            'EE_Email_Field',
223
-            array($table_column, $nice_name, $nullable, $default_value)
224
-        );
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * @param string $table_column
231
-     * @param string $nice_name
232
-     * @param bool   $nullable
233
-     * @param null   $default_value
234
-     * @param array  $allowed_enum_values keys are values to be used in the DB,
235
-     *                                    values are how they should be displayed
236
-     * @return EE_Enum_Integer_Field
237
-     */
238
-    public function createEnumIntegerField(
239
-        $table_column,
240
-        $nice_name,
241
-        $nullable,
242
-        $default_value = null,
243
-        array $allowed_enum_values
244
-    ) {
245
-        return $this->loader->getNew(
246
-            'EE_Enum_Integer_Field',
247
-            array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
248
-        );
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * @param string $table_column
255
-     * @param string $nice_name
256
-     * @param bool   $nullable
257
-     * @param null   $default_value
258
-     * @param array  $allowed_enum_values keys are values to be used in the DB,
259
-     *                                    values are how they should be displayed
260
-     * @return EE_Enum_Text_Field
261
-     */
262
-    public function createEnumTextField(
263
-        $table_column,
264
-        $nice_name,
265
-        $nullable,
266
-        $default_value,
267
-        array $allowed_enum_values
268
-    ) {
269
-        return $this->loader->getNew(
270
-            'EE_Enum_Text_Field',
271
-            array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
272
-        );
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * @param string $table_column
279
-     * @param string $nice_name
280
-     * @param bool   $nullable
281
-     * @param null   $default_value
282
-     * @return EE_Float_Field
283
-     */
284
-    public function createFloatField($table_column, $nice_name, $nullable, $default_value = null)
285
-    {
286
-        return $this->loader->getNew(
287
-            'EE_Float_Field',
288
-            array($table_column, $nice_name, $nullable, $default_value)
289
-        );
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * @param string $table_column
296
-     * @param string $nice_name
297
-     * @param bool   $nullable
298
-     * @param null   $default_value
299
-     * @param string $model_name
300
-     * @return EE_Foreign_Key_Int_Field
301
-     */
302
-    public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name)
303
-    {
304
-        return $this->loader->getNew(
305
-            'EE_Foreign_Key_Int_Field',
306
-            array($table_column, $nice_name, $nullable, $default_value, $model_name)
307
-        );
308
-    }
309
-
310
-
311
-
312
-    /**
313
-     * @param string $table_column
314
-     * @param string $nice_name
315
-     * @param bool   $nullable
316
-     * @param null   $default_value
317
-     * @param string $model_name
318
-     * @return EE_Foreign_Key_String_Field
319
-     */
320
-    public function createForeignKeyStringField(
321
-        $table_column,
322
-        $nice_name,
323
-        $nullable,
324
-        $default_value,
325
-        $model_name
326
-    ) {
327
-        return $this->loader->getNew(
328
-            'EE_Foreign_Key_String_Field',
329
-            array($table_column, $nice_name, $nullable, $default_value, $model_name)
330
-        );
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * @param string $table_column
337
-     * @param string $nice_name
338
-     * @param bool   $nullable
339
-     * @param null   $default_value
340
-     * @return EE_Full_HTML_Field
341
-     */
342
-    public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null)
343
-    {
344
-        return $this->loader->getNew(
345
-            'EE_Full_HTML_Field',
346
-            array($table_column, $nice_name, $nullable, $default_value)
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @param string $table_column
354
-     * @param string $nice_name
355
-     * @param bool   $nullable
356
-     * @param null   $default_value
357
-     * @return EE_Infinite_Integer_Field
358
-     */
359
-    public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null)
360
-    {
361
-        return $this->loader->getNew(
362
-            'EE_Infinite_Integer_Field',
363
-            array($table_column, $nice_name, $nullable, $default_value)
364
-        );
365
-    }
366
-
367
-
368
-
369
-    /**
370
-     * @param string $table_column
371
-     * @param string $nice_name
372
-     * @param bool   $nullable
373
-     * @param null   $default_value
374
-     * @return EE_Integer_Field
375
-     */
376
-    public function createIntegerField($table_column, $nice_name, $nullable, $default_value = null)
377
-    {
378
-        return $this->loader->getNew(
379
-            'EE_Integer_Field',
380
-            array($table_column, $nice_name, $nullable, $default_value)
381
-        );
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     * @param string $table_column
388
-     * @param string $nice_name
389
-     * @param bool   $nullable
390
-     * @param null   $default_value
391
-     * @return EE_Maybe_Serialized_Simple_HTML_Field
392
-     */
393
-    public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null)
394
-    {
395
-        return $this->loader->getNew(
396
-            'EE_Maybe_Serialized_Simple_HTML_Field',
397
-            array($table_column, $nice_name, $nullable, $default_value)
398
-        );
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * @param string $table_column
405
-     * @param string $nice_name
406
-     * @param bool   $nullable
407
-     * @param null   $default_value
408
-     * @return EE_Maybe_Serialized_Text_Field
409
-     */
410
-    public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null)
411
-    {
412
-        return $this->loader->getNew(
413
-            'EE_Maybe_Serialized_Text_Field',
414
-            array($table_column, $nice_name, $nullable, $default_value)
415
-        );
416
-    }
417
-
418
-
419
-
420
-    /**
421
-     * @param string $table_column
422
-     * @param string $nice_name
423
-     * @param bool   $nullable
424
-     * @param null   $default_value
425
-     * @return EE_Money_Field
426
-     */
427
-    public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null)
428
-    {
429
-        return $this->loader->getNew(
430
-            'EE_Money_Field',
431
-            array($table_column, $nice_name, $nullable, $default_value)
432
-        );
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * @param string $table_column
439
-     * @param string $nice_name
440
-     * @param bool   $nullable
441
-     * @param string $default_value
442
-     * @return EE_Plain_Text_Field
443
-     */
444
-    public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '')
445
-    {
446
-        return $this->loader->getNew(
447
-            'EE_Plain_Text_Field',
448
-            array($table_column, $nice_name, $nullable, $default_value)
449
-        );
450
-    }
451
-
452
-
453
-
454
-    /**
455
-     * @param string $table_column
456
-     * @param string $nice_name
457
-     * @param bool   $nullable
458
-     * @param null   $default_value
459
-     * @return EE_Post_Content_Field
460
-     */
461
-    public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null)
462
-    {
463
-        return $this->loader->getNew(
464
-            'EE_Post_Content_Field',
465
-            array($table_column, $nice_name, $nullable, $default_value)
466
-        );
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     * @param string $table_column
473
-     * @param string $nice_name
474
-     * @return EE_Primary_Key_Int_Field
475
-     */
476
-    public function createPrimaryKeyIntField($table_column, $nice_name)
477
-    {
478
-        return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name));
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * @param string $table_column
485
-     * @param string $nice_name
486
-     * @return EE_Primary_Key_String_Field
487
-     */
488
-    public function createPrimaryKeyStringField($table_column, $nice_name)
489
-    {
490
-        return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name));
491
-    }
492
-
493
-
494
-
495
-    /**
496
-     * @param string $table_column
497
-     * @param string $nice_name
498
-     * @param bool   $nullable
499
-     * @param null   $default_value
500
-     * @return EE_Serialized_Text_Field
501
-     */
502
-    public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null)
503
-    {
504
-        return $this->loader->getNew(
505
-            'EE_Serialized_Text_Field',
506
-            array($table_column, $nice_name, $nullable, $default_value)
507
-        );
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param string $table_column
514
-     * @param string $nice_name
515
-     * @param bool   $nullable
516
-     * @param null   $default_value
517
-     * @return EE_Simple_HTML_Field
518
-     */
519
-    public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null)
520
-    {
521
-        return $this->loader->getNew(
522
-            'EE_Simple_HTML_Field',
523
-            array($table_column, $nice_name, $nullable, $default_value)
524
-        );
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * @param string $table_column
531
-     * @param string $nice_name
532
-     * @param bool   $nullable
533
-     * @param null   $default_value
534
-     * @return EE_Slug_Field
535
-     */
536
-    public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null)
537
-    {
538
-        return $this->loader->getNew(
539
-            'EE_Slug_Field',
540
-            array($table_column, $nice_name, $nullable, $default_value)
541
-        );
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     * @param string $table_column
548
-     * @param string $nice_name
549
-     * @param bool   $nullable
550
-     * @param null   $default_value
551
-     * @return EE_Trashed_Flag_Field
552
-     */
553
-    public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null)
554
-    {
555
-        return $this->loader->getNew(
556
-            'EE_Trashed_Flag_Field',
557
-            array($table_column, $nice_name, $nullable, $default_value)
558
-        );
559
-    }
560
-
561
-
562
-
563
-    /**
564
-     * @param string $table_column
565
-     * @param string $nice_name
566
-     * @param bool   $nullable
567
-     * @param mixed  $default_value
568
-     * @param array  $values        If additional stati are to be used other than the default WP statuses,
569
-     *                              then they can be registered via this property.
570
-     *                              The format of the array should be as follows:
571
-     *  array(
572
-     *      'status_reference' => array(
573
-     *          'label' => __('Status Reference Label', 'event_espresso'),
574
-     *          'public' => true,                 // whether this status should be shown on the frontend of the site
575
-     *          'exclude_from_search' => false,   // whether this status should be excluded from wp searches
576
-     *          'show_in_admin_all_list' => true, // whether this status is included in queries
577
-     *                                               for the admin "all" view in list table views.
578
-     *          'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top
579
-     *                                                  of the admin list tables (i.e. Status Reference(2) )
580
-     *          'label_count' => _n_noop(
581
-     *              'Status Reference <span class="count">(%s)</span>',
582
-     *              'Status References <span class="count">(%s)</span>'
583
-     *          ),                                   // the text to display on the admin screen
584
-     *                                                  ( or you won't see your status count ).
585
-     *      )
586
-     *  )
587
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
588
-     * @return EE_WP_Post_Status_Field
589
-     */
590
-    public function createWpPostStatusField(
591
-        $table_column,
592
-        $nice_name,
593
-        $nullable,
594
-        $default_value = null,
595
-        array $values = array()
596
-    ) {
597
-        return $this->loader->getNew(
598
-            'EE_WP_Post_Status_Field',
599
-            array($table_column, $nice_name, $nullable, $default_value, $values)
600
-        );
601
-    }
602
-
603
-
604
-
605
-    /**
606
-     * @param string $post_type
607
-     * @return EE_WP_Post_Type_Field
608
-     */
609
-    public function createWpPostTypeField($post_type)
610
-    {
611
-        return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type));
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * @param string $table_column
618
-     * @param string $nice_name
619
-     * @param bool   $nullable
620
-     * @return EE_WP_User_Field
621
-     */
622
-    public function createWpUserField($table_column, $nice_name, $nullable)
623
-    {
624
-        return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable));
625
-    }
56
+	/**
57
+	 * @var LoaderInterface $loader
58
+	 */
59
+	private $loader;
60
+
61
+
62
+
63
+	/**
64
+	 * ModelFieldFactory constructor.
65
+	 *
66
+	 * @param LoaderInterface $loader
67
+	 */
68
+	public function __construct(LoaderInterface $loader)
69
+	{
70
+		$this->loader = $loader;
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 * @param string $table_column
77
+	 * @param string $nice_name
78
+	 * @param bool   $nullable
79
+	 * @param null   $default_value
80
+	 * @return EE_All_Caps_Text_Field
81
+	 */
82
+	public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null)
83
+	{
84
+		return $this->loader->getNew(
85
+			'EE_All_Caps_Text_Field',
86
+			array($table_column, $nice_name, $nullable, $default_value)
87
+		);
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * @param string $table_column
94
+	 * @param string $nice_name
95
+	 * @param bool   $nullable
96
+	 * @param null   $default_value
97
+	 * @param string $model_name
98
+	 * @return EE_Any_Foreign_Model_Name_Field
99
+	 */
100
+	public function createAnyForeignModelNameField(
101
+		$table_column,
102
+		$nice_name,
103
+		$nullable,
104
+		$default_value = null,
105
+		$model_name
106
+	) {
107
+		return $this->loader->getNew(
108
+			'EE_Any_Foreign_Model_Name_Field',
109
+			array($table_column, $nice_name, $nullable, $default_value, $model_name)
110
+		);
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param string $table_column
117
+	 * @param string $nice_name
118
+	 * @param bool   $nullable
119
+	 * @param null   $default_value
120
+	 * @return EE_Boolean_Field
121
+	 */
122
+	public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null)
123
+	{
124
+		return $this->loader->getNew(
125
+			'EE_Boolean_Field',
126
+			array($table_column, $nice_name, $nullable, $default_value)
127
+		);
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @param string $table_column
134
+	 * @param string $nice_name
135
+	 * @param string $timezone_string
136
+	 * @param bool   $nullable
137
+	 * @param string $default_value
138
+	 * @throws EE_Error
139
+	 * @throws InvalidArgumentException
140
+	 * @return EE_Datetime_Field
141
+	 */
142
+	public function createDatetimeField(
143
+		$table_column,
144
+		$nice_name,
145
+		$nullable = false,
146
+		$default_value = EE_Datetime_Field::now
147
+	) {
148
+		return $this->loader->getNew(
149
+			'EE_Datetime_Field',
150
+			array(
151
+				$table_column,
152
+				$nice_name,
153
+				$nullable,
154
+				$default_value
155
+			)
156
+		);
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * @param string $table_column
163
+	 * @param string $nice_name
164
+	 * @param bool   $nullable
165
+	 * @param null   $default_value
166
+	 * @return EE_DB_Only_Float_Field
167
+	 */
168
+	public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null)
169
+	{
170
+		return $this->loader->getNew(
171
+			'EE_DB_Only_Float_Field',
172
+			array($table_column, $nice_name, $nullable, $default_value)
173
+		);
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * @param string $table_column
180
+	 * @param string $nice_name
181
+	 * @param bool   $nullable
182
+	 * @param null   $default_value
183
+	 * @return EE_DB_Only_Int_Field
184
+	 */
185
+	public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null)
186
+	{
187
+		return $this->loader->getNew(
188
+			'EE_DB_Only_Int_Field',
189
+			array($table_column, $nice_name, $nullable, $default_value)
190
+		);
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * @param string $table_column
197
+	 * @param string $nice_name
198
+	 * @param bool   $nullable
199
+	 * @param null   $default_value
200
+	 * @return EE_DB_Only_Text_Field
201
+	 */
202
+	public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null)
203
+	{
204
+		return $this->loader->getNew(
205
+			'EE_DB_Only_Text_Field',
206
+			array($table_column, $nice_name, $nullable, $default_value)
207
+		);
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * @param string $table_column
214
+	 * @param string $nice_name
215
+	 * @param bool   $nullable
216
+	 * @param string $default_value
217
+	 * @return EE_Email_Field
218
+	 */
219
+	public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '')
220
+	{
221
+		return $this->loader->getNew(
222
+			'EE_Email_Field',
223
+			array($table_column, $nice_name, $nullable, $default_value)
224
+		);
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * @param string $table_column
231
+	 * @param string $nice_name
232
+	 * @param bool   $nullable
233
+	 * @param null   $default_value
234
+	 * @param array  $allowed_enum_values keys are values to be used in the DB,
235
+	 *                                    values are how they should be displayed
236
+	 * @return EE_Enum_Integer_Field
237
+	 */
238
+	public function createEnumIntegerField(
239
+		$table_column,
240
+		$nice_name,
241
+		$nullable,
242
+		$default_value = null,
243
+		array $allowed_enum_values
244
+	) {
245
+		return $this->loader->getNew(
246
+			'EE_Enum_Integer_Field',
247
+			array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
248
+		);
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * @param string $table_column
255
+	 * @param string $nice_name
256
+	 * @param bool   $nullable
257
+	 * @param null   $default_value
258
+	 * @param array  $allowed_enum_values keys are values to be used in the DB,
259
+	 *                                    values are how they should be displayed
260
+	 * @return EE_Enum_Text_Field
261
+	 */
262
+	public function createEnumTextField(
263
+		$table_column,
264
+		$nice_name,
265
+		$nullable,
266
+		$default_value,
267
+		array $allowed_enum_values
268
+	) {
269
+		return $this->loader->getNew(
270
+			'EE_Enum_Text_Field',
271
+			array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
272
+		);
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * @param string $table_column
279
+	 * @param string $nice_name
280
+	 * @param bool   $nullable
281
+	 * @param null   $default_value
282
+	 * @return EE_Float_Field
283
+	 */
284
+	public function createFloatField($table_column, $nice_name, $nullable, $default_value = null)
285
+	{
286
+		return $this->loader->getNew(
287
+			'EE_Float_Field',
288
+			array($table_column, $nice_name, $nullable, $default_value)
289
+		);
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * @param string $table_column
296
+	 * @param string $nice_name
297
+	 * @param bool   $nullable
298
+	 * @param null   $default_value
299
+	 * @param string $model_name
300
+	 * @return EE_Foreign_Key_Int_Field
301
+	 */
302
+	public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name)
303
+	{
304
+		return $this->loader->getNew(
305
+			'EE_Foreign_Key_Int_Field',
306
+			array($table_column, $nice_name, $nullable, $default_value, $model_name)
307
+		);
308
+	}
309
+
310
+
311
+
312
+	/**
313
+	 * @param string $table_column
314
+	 * @param string $nice_name
315
+	 * @param bool   $nullable
316
+	 * @param null   $default_value
317
+	 * @param string $model_name
318
+	 * @return EE_Foreign_Key_String_Field
319
+	 */
320
+	public function createForeignKeyStringField(
321
+		$table_column,
322
+		$nice_name,
323
+		$nullable,
324
+		$default_value,
325
+		$model_name
326
+	) {
327
+		return $this->loader->getNew(
328
+			'EE_Foreign_Key_String_Field',
329
+			array($table_column, $nice_name, $nullable, $default_value, $model_name)
330
+		);
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * @param string $table_column
337
+	 * @param string $nice_name
338
+	 * @param bool   $nullable
339
+	 * @param null   $default_value
340
+	 * @return EE_Full_HTML_Field
341
+	 */
342
+	public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null)
343
+	{
344
+		return $this->loader->getNew(
345
+			'EE_Full_HTML_Field',
346
+			array($table_column, $nice_name, $nullable, $default_value)
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @param string $table_column
354
+	 * @param string $nice_name
355
+	 * @param bool   $nullable
356
+	 * @param null   $default_value
357
+	 * @return EE_Infinite_Integer_Field
358
+	 */
359
+	public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null)
360
+	{
361
+		return $this->loader->getNew(
362
+			'EE_Infinite_Integer_Field',
363
+			array($table_column, $nice_name, $nullable, $default_value)
364
+		);
365
+	}
366
+
367
+
368
+
369
+	/**
370
+	 * @param string $table_column
371
+	 * @param string $nice_name
372
+	 * @param bool   $nullable
373
+	 * @param null   $default_value
374
+	 * @return EE_Integer_Field
375
+	 */
376
+	public function createIntegerField($table_column, $nice_name, $nullable, $default_value = null)
377
+	{
378
+		return $this->loader->getNew(
379
+			'EE_Integer_Field',
380
+			array($table_column, $nice_name, $nullable, $default_value)
381
+		);
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 * @param string $table_column
388
+	 * @param string $nice_name
389
+	 * @param bool   $nullable
390
+	 * @param null   $default_value
391
+	 * @return EE_Maybe_Serialized_Simple_HTML_Field
392
+	 */
393
+	public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null)
394
+	{
395
+		return $this->loader->getNew(
396
+			'EE_Maybe_Serialized_Simple_HTML_Field',
397
+			array($table_column, $nice_name, $nullable, $default_value)
398
+		);
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * @param string $table_column
405
+	 * @param string $nice_name
406
+	 * @param bool   $nullable
407
+	 * @param null   $default_value
408
+	 * @return EE_Maybe_Serialized_Text_Field
409
+	 */
410
+	public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null)
411
+	{
412
+		return $this->loader->getNew(
413
+			'EE_Maybe_Serialized_Text_Field',
414
+			array($table_column, $nice_name, $nullable, $default_value)
415
+		);
416
+	}
417
+
418
+
419
+
420
+	/**
421
+	 * @param string $table_column
422
+	 * @param string $nice_name
423
+	 * @param bool   $nullable
424
+	 * @param null   $default_value
425
+	 * @return EE_Money_Field
426
+	 */
427
+	public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null)
428
+	{
429
+		return $this->loader->getNew(
430
+			'EE_Money_Field',
431
+			array($table_column, $nice_name, $nullable, $default_value)
432
+		);
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * @param string $table_column
439
+	 * @param string $nice_name
440
+	 * @param bool   $nullable
441
+	 * @param string $default_value
442
+	 * @return EE_Plain_Text_Field
443
+	 */
444
+	public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '')
445
+	{
446
+		return $this->loader->getNew(
447
+			'EE_Plain_Text_Field',
448
+			array($table_column, $nice_name, $nullable, $default_value)
449
+		);
450
+	}
451
+
452
+
453
+
454
+	/**
455
+	 * @param string $table_column
456
+	 * @param string $nice_name
457
+	 * @param bool   $nullable
458
+	 * @param null   $default_value
459
+	 * @return EE_Post_Content_Field
460
+	 */
461
+	public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null)
462
+	{
463
+		return $this->loader->getNew(
464
+			'EE_Post_Content_Field',
465
+			array($table_column, $nice_name, $nullable, $default_value)
466
+		);
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 * @param string $table_column
473
+	 * @param string $nice_name
474
+	 * @return EE_Primary_Key_Int_Field
475
+	 */
476
+	public function createPrimaryKeyIntField($table_column, $nice_name)
477
+	{
478
+		return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name));
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * @param string $table_column
485
+	 * @param string $nice_name
486
+	 * @return EE_Primary_Key_String_Field
487
+	 */
488
+	public function createPrimaryKeyStringField($table_column, $nice_name)
489
+	{
490
+		return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name));
491
+	}
492
+
493
+
494
+
495
+	/**
496
+	 * @param string $table_column
497
+	 * @param string $nice_name
498
+	 * @param bool   $nullable
499
+	 * @param null   $default_value
500
+	 * @return EE_Serialized_Text_Field
501
+	 */
502
+	public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null)
503
+	{
504
+		return $this->loader->getNew(
505
+			'EE_Serialized_Text_Field',
506
+			array($table_column, $nice_name, $nullable, $default_value)
507
+		);
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param string $table_column
514
+	 * @param string $nice_name
515
+	 * @param bool   $nullable
516
+	 * @param null   $default_value
517
+	 * @return EE_Simple_HTML_Field
518
+	 */
519
+	public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null)
520
+	{
521
+		return $this->loader->getNew(
522
+			'EE_Simple_HTML_Field',
523
+			array($table_column, $nice_name, $nullable, $default_value)
524
+		);
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * @param string $table_column
531
+	 * @param string $nice_name
532
+	 * @param bool   $nullable
533
+	 * @param null   $default_value
534
+	 * @return EE_Slug_Field
535
+	 */
536
+	public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null)
537
+	{
538
+		return $this->loader->getNew(
539
+			'EE_Slug_Field',
540
+			array($table_column, $nice_name, $nullable, $default_value)
541
+		);
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 * @param string $table_column
548
+	 * @param string $nice_name
549
+	 * @param bool   $nullable
550
+	 * @param null   $default_value
551
+	 * @return EE_Trashed_Flag_Field
552
+	 */
553
+	public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null)
554
+	{
555
+		return $this->loader->getNew(
556
+			'EE_Trashed_Flag_Field',
557
+			array($table_column, $nice_name, $nullable, $default_value)
558
+		);
559
+	}
560
+
561
+
562
+
563
+	/**
564
+	 * @param string $table_column
565
+	 * @param string $nice_name
566
+	 * @param bool   $nullable
567
+	 * @param mixed  $default_value
568
+	 * @param array  $values        If additional stati are to be used other than the default WP statuses,
569
+	 *                              then they can be registered via this property.
570
+	 *                              The format of the array should be as follows:
571
+	 *  array(
572
+	 *      'status_reference' => array(
573
+	 *          'label' => __('Status Reference Label', 'event_espresso'),
574
+	 *          'public' => true,                 // whether this status should be shown on the frontend of the site
575
+	 *          'exclude_from_search' => false,   // whether this status should be excluded from wp searches
576
+	 *          'show_in_admin_all_list' => true, // whether this status is included in queries
577
+	 *                                               for the admin "all" view in list table views.
578
+	 *          'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top
579
+	 *                                                  of the admin list tables (i.e. Status Reference(2) )
580
+	 *          'label_count' => _n_noop(
581
+	 *              'Status Reference <span class="count">(%s)</span>',
582
+	 *              'Status References <span class="count">(%s)</span>'
583
+	 *          ),                                   // the text to display on the admin screen
584
+	 *                                                  ( or you won't see your status count ).
585
+	 *      )
586
+	 *  )
587
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
588
+	 * @return EE_WP_Post_Status_Field
589
+	 */
590
+	public function createWpPostStatusField(
591
+		$table_column,
592
+		$nice_name,
593
+		$nullable,
594
+		$default_value = null,
595
+		array $values = array()
596
+	) {
597
+		return $this->loader->getNew(
598
+			'EE_WP_Post_Status_Field',
599
+			array($table_column, $nice_name, $nullable, $default_value, $values)
600
+		);
601
+	}
602
+
603
+
604
+
605
+	/**
606
+	 * @param string $post_type
607
+	 * @return EE_WP_Post_Type_Field
608
+	 */
609
+	public function createWpPostTypeField($post_type)
610
+	{
611
+		return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type));
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * @param string $table_column
618
+	 * @param string $nice_name
619
+	 * @param bool   $nullable
620
+	 * @return EE_WP_User_Field
621
+	 */
622
+	public function createWpUserField($table_column, $nice_name, $nullable)
623
+	{
624
+		return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable));
625
+	}
626 626
 
627 627
 
628 628
 
Please login to merge, or discard this patch.
core/services/Benchmark.php 2 patches
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -17,303 +17,303 @@
 block discarded – undo
17 17
 class Benchmark
18 18
 {
19 19
 
20
-    /**
21
-     * array containing the start time for the timers
22
-     */
23
-    private static $start_times;
24
-
25
-    /**
26
-     * array containing all the timer'd times, which can be outputted via show_times()
27
-     */
28
-    private static $times = array();
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    protected static $memory_usage = array();
34
-
35
-
36
-
37
-    /**
38
-     * whether to benchmark code or not
39
-     */
40
-    public static function doNotRun()
41
-    {
42
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * resetTimes
49
-     */
50
-    public static function resetTimes()
51
-    {
52
-        Benchmark::$times = array();
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
-     *
60
-     * @param null $timer_name
61
-     */
62
-    public static function startTimer($timer_name = null)
63
-    {
64
-        if (Benchmark::doNotRun()) {
65
-            return;
66
-        }
67
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
-        Benchmark::$start_times[$timer_name] = microtime(true);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
-     *
76
-     * @param string $timer_name
77
-     */
78
-    public static function stopTimer($timer_name = '')
79
-    {
80
-        if (Benchmark::doNotRun()) {
81
-            return;
82
-        }
83
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
-        if (isset(Benchmark::$start_times[$timer_name])) {
85
-            $start_time = Benchmark::$start_times[$timer_name];
86
-            unset(Benchmark::$start_times[$timer_name]);
87
-        } else {
88
-            $start_time = array_pop(Benchmark::$start_times);
89
-        }
90
-        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * Measure the memory usage by PHP so far.
97
-     *
98
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
-     * @param bool    $formatted
101
-     * @return void
102
-     */
103
-    public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
104
-    {
105
-        if (Benchmark::doNotRun()) {
106
-            return;
107
-        }
108
-        $memory_used = Benchmark::convert(memory_get_peak_usage(true));
109
-        Benchmark::$memory_usage[$label] = $memory_used;
110
-        if ($output_now) {
111
-            echo $formatted
112
-                ? "<br>{$label} : {$memory_used}"
113
-                : "\n {$label} : {$memory_used}";
114
-        }
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * will display the benchmarking results at shutdown
121
-     *
122
-     * @param bool $formatted
123
-     * @return void
124
-     */
125
-    public static function displayResultsAtShutdown($formatted = true)
126
-    {
127
-        add_action(
128
-            'shutdown',
129
-            function () use ($formatted) {
130
-                Benchmark::displayResults(true, $formatted);
131
-            }
132
-        );
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * will display the benchmarking results at shutdown
139
-     *
140
-     * @param string $filepath
141
-     * @param bool   $formatted
142
-     * @param bool   $append
143
-     * @return void
144
-     */
145
-    public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
146
-    {
147
-        add_action(
148
-            'shutdown',
149
-            function () use ($filepath, $formatted, $append) {
150
-                Benchmark::writeResultsToFile($filepath, $formatted, $append);
151
-            }
152
-        );
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * @param bool $formatted
159
-     * @return string
160
-     */
161
-    private static function generateResults($formatted = true)
162
-    {
163
-        if (Benchmark::doNotRun()) {
164
-            return '';
165
-        }
166
-        $output = '';
167
-        if (! empty(Benchmark::$times)) {
168
-            $total = 0;
169
-            $output .= $formatted
170
-                ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
171
-                : '';
172
-            foreach (Benchmark::$times as $timer_name => $total_time) {
173
-                $output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
174
-                $output .= $formatted ? '<br />'  : "\n";
175
-                $total += $total_time;
176
-            }
177
-            if($formatted) {
178
-                $output .= '<br />';
179
-                $output .= '<h4>TOTAL TIME</h4>';
180
-                $output .= Benchmark::formatTime('', $total, $formatted);
181
-                $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
182
-                $output .= '<br />';
183
-                $output .= '<h5>Performance scale (from best to worse)</h5>';
184
-                $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
185
-                $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
186
-                $output .= '<span style="color:limegreen">Like...groovy!</span><br />';
187
-                $output .= '<span style="color:gold">Ruh Oh</span><br />';
188
-                $output .= '<span style="color:darkorange">Zoinks!</span><br />';
189
-                $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
190
-            }
191
-        }
192
-        if (! empty(Benchmark::$memory_usage)) {
193
-            $output .= $formatted
194
-                ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage)
195
-                : implode("\n", Benchmark::$memory_usage);
196
-        }
197
-        if (empty($output)) {
198
-            return '';
199
-        }
200
-        $output = $formatted
201
-            ? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
202
-              . (is_admin()
203
-                ? ' margin:2em 2em 2em 180px;'
204
-                : ' margin:2em;')
205
-              . ' padding:2em;">'
206
-              . '<h4>BENCHMARKING</h4>'
207
-              . $output
208
-              . '</div>'
209
-            : $output;
210
-        return $output;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * @param bool $echo
217
-     * @param bool $formatted
218
-     * @return string
219
-     */
220
-    public static function displayResults($echo = true, $formatted = true)
221
-    {
222
-        $results = Benchmark::generateResults($formatted);
223
-        if ($echo) {
224
-            echo $results;
225
-            $results = '';
226
-        }
227
-        return $results;
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * @param string $filepath
234
-     * @param bool   $formatted
235
-     * @param bool   $append
236
-     */
237
-    public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
238
-    {
239
-        $filepath = ! empty($filepath) && is_readable(dirname($filepath))
240
-            ? $filepath
241
-            : '';
242
-        if( empty($filepath)) {
243
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
244
-        }
245
-        file_put_contents(
246
-            $filepath,
247
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
248
-            $append ? FILE_APPEND | LOCK_EX : LOCK_EX
249
-        );
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
256
-     *
257
-     * @param int $size
258
-     * @return string
259
-     */
260
-    public static function convert($size)
261
-    {
262
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
263
-        return round(
264
-            $size / pow(1024, $i = floor(log($size, 1024))),
265
-            2
266
-        ) . ' ' . $unit[absint($i)];
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * @param string $timer_name
273
-     * @param float  $total_time
274
-     * @param bool   $formatted
275
-     * @return string
276
-     */
277
-    public static function formatTime($timer_name, $total_time, $formatted = true)
278
-    {
279
-        $total_time *= 1000;
280
-        switch ($total_time) {
281
-            case $total_time > 12500 :
282
-                $color = 'red';
283
-                $bold = 'bold';
284
-                break;
285
-            case $total_time > 2500 :
286
-                $color = 'darkorange';
287
-                $bold = 'bold';
288
-                break;
289
-            case $total_time > 500 :
290
-                $color = 'gold';
291
-                $bold = 'bold';
292
-                break;
293
-            case $total_time > 100 :
294
-                $color = 'limegreen';
295
-                $bold = 'normal';
296
-                break;
297
-            case $total_time > 20 :
298
-                $color = 'deepskyblue';
299
-                $bold = 'normal';
300
-                break;
301
-            default :
302
-                $color = 'mediumpurple';
303
-                $bold = 'normal';
304
-                break;
305
-        }
306
-        return $formatted
307
-            ? '<span style="min-width: 10px; margin:0 1em; color:'
308
-               . $color
309
-               . '; font-weight:'
310
-               . $bold
311
-               . '; font-size:1.2em;">'
312
-               . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
313
-               . '</span> '
314
-               . $timer_name
315
-            :  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
316
-    }
20
+	/**
21
+	 * array containing the start time for the timers
22
+	 */
23
+	private static $start_times;
24
+
25
+	/**
26
+	 * array containing all the timer'd times, which can be outputted via show_times()
27
+	 */
28
+	private static $times = array();
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	protected static $memory_usage = array();
34
+
35
+
36
+
37
+	/**
38
+	 * whether to benchmark code or not
39
+	 */
40
+	public static function doNotRun()
41
+	{
42
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * resetTimes
49
+	 */
50
+	public static function resetTimes()
51
+	{
52
+		Benchmark::$times = array();
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
+	 *
60
+	 * @param null $timer_name
61
+	 */
62
+	public static function startTimer($timer_name = null)
63
+	{
64
+		if (Benchmark::doNotRun()) {
65
+			return;
66
+		}
67
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
+		Benchmark::$start_times[$timer_name] = microtime(true);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
+	 *
76
+	 * @param string $timer_name
77
+	 */
78
+	public static function stopTimer($timer_name = '')
79
+	{
80
+		if (Benchmark::doNotRun()) {
81
+			return;
82
+		}
83
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
+		if (isset(Benchmark::$start_times[$timer_name])) {
85
+			$start_time = Benchmark::$start_times[$timer_name];
86
+			unset(Benchmark::$start_times[$timer_name]);
87
+		} else {
88
+			$start_time = array_pop(Benchmark::$start_times);
89
+		}
90
+		Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * Measure the memory usage by PHP so far.
97
+	 *
98
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
+	 * @param bool    $formatted
101
+	 * @return void
102
+	 */
103
+	public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
104
+	{
105
+		if (Benchmark::doNotRun()) {
106
+			return;
107
+		}
108
+		$memory_used = Benchmark::convert(memory_get_peak_usage(true));
109
+		Benchmark::$memory_usage[$label] = $memory_used;
110
+		if ($output_now) {
111
+			echo $formatted
112
+				? "<br>{$label} : {$memory_used}"
113
+				: "\n {$label} : {$memory_used}";
114
+		}
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * will display the benchmarking results at shutdown
121
+	 *
122
+	 * @param bool $formatted
123
+	 * @return void
124
+	 */
125
+	public static function displayResultsAtShutdown($formatted = true)
126
+	{
127
+		add_action(
128
+			'shutdown',
129
+			function () use ($formatted) {
130
+				Benchmark::displayResults(true, $formatted);
131
+			}
132
+		);
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * will display the benchmarking results at shutdown
139
+	 *
140
+	 * @param string $filepath
141
+	 * @param bool   $formatted
142
+	 * @param bool   $append
143
+	 * @return void
144
+	 */
145
+	public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
146
+	{
147
+		add_action(
148
+			'shutdown',
149
+			function () use ($filepath, $formatted, $append) {
150
+				Benchmark::writeResultsToFile($filepath, $formatted, $append);
151
+			}
152
+		);
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * @param bool $formatted
159
+	 * @return string
160
+	 */
161
+	private static function generateResults($formatted = true)
162
+	{
163
+		if (Benchmark::doNotRun()) {
164
+			return '';
165
+		}
166
+		$output = '';
167
+		if (! empty(Benchmark::$times)) {
168
+			$total = 0;
169
+			$output .= $formatted
170
+				? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
171
+				: '';
172
+			foreach (Benchmark::$times as $timer_name => $total_time) {
173
+				$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
174
+				$output .= $formatted ? '<br />'  : "\n";
175
+				$total += $total_time;
176
+			}
177
+			if($formatted) {
178
+				$output .= '<br />';
179
+				$output .= '<h4>TOTAL TIME</h4>';
180
+				$output .= Benchmark::formatTime('', $total, $formatted);
181
+				$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
182
+				$output .= '<br />';
183
+				$output .= '<h5>Performance scale (from best to worse)</h5>';
184
+				$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
185
+				$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
186
+				$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
187
+				$output .= '<span style="color:gold">Ruh Oh</span><br />';
188
+				$output .= '<span style="color:darkorange">Zoinks!</span><br />';
189
+				$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
190
+			}
191
+		}
192
+		if (! empty(Benchmark::$memory_usage)) {
193
+			$output .= $formatted
194
+				? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage)
195
+				: implode("\n", Benchmark::$memory_usage);
196
+		}
197
+		if (empty($output)) {
198
+			return '';
199
+		}
200
+		$output = $formatted
201
+			? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
202
+			  . (is_admin()
203
+				? ' margin:2em 2em 2em 180px;'
204
+				: ' margin:2em;')
205
+			  . ' padding:2em;">'
206
+			  . '<h4>BENCHMARKING</h4>'
207
+			  . $output
208
+			  . '</div>'
209
+			: $output;
210
+		return $output;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * @param bool $echo
217
+	 * @param bool $formatted
218
+	 * @return string
219
+	 */
220
+	public static function displayResults($echo = true, $formatted = true)
221
+	{
222
+		$results = Benchmark::generateResults($formatted);
223
+		if ($echo) {
224
+			echo $results;
225
+			$results = '';
226
+		}
227
+		return $results;
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * @param string $filepath
234
+	 * @param bool   $formatted
235
+	 * @param bool   $append
236
+	 */
237
+	public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
238
+	{
239
+		$filepath = ! empty($filepath) && is_readable(dirname($filepath))
240
+			? $filepath
241
+			: '';
242
+		if( empty($filepath)) {
243
+			$filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
244
+		}
245
+		file_put_contents(
246
+			$filepath,
247
+			"\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
248
+			$append ? FILE_APPEND | LOCK_EX : LOCK_EX
249
+		);
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
256
+	 *
257
+	 * @param int $size
258
+	 * @return string
259
+	 */
260
+	public static function convert($size)
261
+	{
262
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
263
+		return round(
264
+			$size / pow(1024, $i = floor(log($size, 1024))),
265
+			2
266
+		) . ' ' . $unit[absint($i)];
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * @param string $timer_name
273
+	 * @param float  $total_time
274
+	 * @param bool   $formatted
275
+	 * @return string
276
+	 */
277
+	public static function formatTime($timer_name, $total_time, $formatted = true)
278
+	{
279
+		$total_time *= 1000;
280
+		switch ($total_time) {
281
+			case $total_time > 12500 :
282
+				$color = 'red';
283
+				$bold = 'bold';
284
+				break;
285
+			case $total_time > 2500 :
286
+				$color = 'darkorange';
287
+				$bold = 'bold';
288
+				break;
289
+			case $total_time > 500 :
290
+				$color = 'gold';
291
+				$bold = 'bold';
292
+				break;
293
+			case $total_time > 100 :
294
+				$color = 'limegreen';
295
+				$bold = 'normal';
296
+				break;
297
+			case $total_time > 20 :
298
+				$color = 'deepskyblue';
299
+				$bold = 'normal';
300
+				break;
301
+			default :
302
+				$color = 'mediumpurple';
303
+				$bold = 'normal';
304
+				break;
305
+		}
306
+		return $formatted
307
+			? '<span style="min-width: 10px; margin:0 1em; color:'
308
+			   . $color
309
+			   . '; font-weight:'
310
+			   . $bold
311
+			   . '; font-size:1.2em;">'
312
+			   . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
313
+			   . '</span> '
314
+			   . $timer_name
315
+			:  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
316
+	}
317 317
 
318 318
 
319 319
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     {
127 127
         add_action(
128 128
             'shutdown',
129
-            function () use ($formatted) {
129
+            function() use ($formatted) {
130 130
                 Benchmark::displayResults(true, $formatted);
131 131
             }
132 132
         );
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     {
147 147
         add_action(
148 148
             'shutdown',
149
-            function () use ($filepath, $formatted, $append) {
149
+            function() use ($filepath, $formatted, $append) {
150 150
                 Benchmark::writeResultsToFile($filepath, $formatted, $append);
151 151
             }
152 152
         );
@@ -164,17 +164,17 @@  discard block
 block discarded – undo
164 164
             return '';
165 165
         }
166 166
         $output = '';
167
-        if (! empty(Benchmark::$times)) {
167
+        if ( ! empty(Benchmark::$times)) {
168 168
             $total = 0;
169 169
             $output .= $formatted
170 170
                 ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
171 171
                 : '';
172 172
             foreach (Benchmark::$times as $timer_name => $total_time) {
173 173
                 $output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
174
-                $output .= $formatted ? '<br />'  : "\n";
174
+                $output .= $formatted ? '<br />' : "\n";
175 175
                 $total += $total_time;
176 176
             }
177
-            if($formatted) {
177
+            if ($formatted) {
178 178
                 $output .= '<br />';
179 179
                 $output .= '<h4>TOTAL TIME</h4>';
180 180
                 $output .= Benchmark::formatTime('', $total, $formatted);
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
                 $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
190 190
             }
191 191
         }
192
-        if (! empty(Benchmark::$memory_usage)) {
192
+        if ( ! empty(Benchmark::$memory_usage)) {
193 193
             $output .= $formatted
194
-                ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage)
194
+                ? '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage)
195 195
                 : implode("\n", Benchmark::$memory_usage);
196 196
         }
197 197
         if (empty($output)) {
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
         $filepath = ! empty($filepath) && is_readable(dirname($filepath))
240 240
             ? $filepath
241 241
             : '';
242
-        if( empty($filepath)) {
243
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
242
+        if (empty($filepath)) {
243
+            $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html';
244 244
         }
245 245
         file_put_contents(
246 246
             $filepath,
247
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
247
+            "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted),
248 248
             $append ? FILE_APPEND | LOCK_EX : LOCK_EX
249 249
         );
250 250
     }
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
         return round(
264 264
             $size / pow(1024, $i = floor(log($size, 1024))),
265 265
             2
266
-        ) . ' ' . $unit[absint($i)];
266
+        ).' '.$unit[absint($i)];
267 267
     }
268 268
 
269 269
 
Please login to merge, or discard this patch.
core/services/loaders/LoaderDecoratorInterface.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -9,20 +9,20 @@
 block discarded – undo
9 9
 interface LoaderDecoratorInterface
10 10
 {
11 11
 
12
-    /**
13
-     * @param string $fqcn
14
-     * @param array  $arguments
15
-     * @param bool   $shared
16
-     * @return mixed
17
-     */
18
-    public function load($fqcn, $arguments = array(), $shared = true);
12
+	/**
13
+	 * @param string $fqcn
14
+	 * @param array  $arguments
15
+	 * @param bool   $shared
16
+	 * @return mixed
17
+	 */
18
+	public function load($fqcn, $arguments = array(), $shared = true);
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * calls reset() on loader if method exists
24
-     */
25
-    public function reset();
22
+	/**
23
+	 * calls reset() on loader if method exists
24
+	 */
25
+	public function reset();
26 26
 
27 27
 }
28 28
 // End of file LoaderInterface.php
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Indentation   +1169 added lines, -1169 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,1173 +17,1173 @@  discard block
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * This is used to hold the reports template data which is setup early in the request.
22
-     *
23
-     * @type array
24
-     */
25
-    protected $_reports_template_data = array();
26
-
27
-
28
-
29
-    /**
30
-     * Extend_Registrations_Admin_Page constructor.
31
-     *
32
-     * @param bool $routing
33
-     */
34
-    public function __construct($routing = true)
35
-    {
36
-        parent::__construct($routing);
37
-        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
-        }
42
-    }
43
-
44
-
45
-
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
-        // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
54
-        // 	? $this->_req_data['post'] : $att_id;
55
-        $new_page_routes = array(
56
-            'reports'                  => array(
57
-                'func'       => '_registration_reports',
58
-                'capability' => 'ee_read_registrations',
59
-            ),
60
-            'registration_checkins'    => array(
61
-                'func'       => '_registration_checkin_list_table',
62
-                'capability' => 'ee_read_checkins',
63
-            ),
64
-            'newsletter_selected_send' => array(
65
-                'func'       => '_newsletter_selected_send',
66
-                'noheader'   => true,
67
-                'capability' => 'ee_send_message',
68
-            ),
69
-            'delete_checkin_rows'      => array(
70
-                'func'       => '_delete_checkin_rows',
71
-                'noheader'   => true,
72
-                'capability' => 'ee_delete_checkins',
73
-            ),
74
-            'delete_checkin_row'       => array(
75
-                'func'       => '_delete_checkin_row',
76
-                'noheader'   => true,
77
-                'capability' => 'ee_delete_checkin',
78
-                'obj_id'     => $reg_id,
79
-            ),
80
-            'toggle_checkin_status'    => array(
81
-                'func'       => '_toggle_checkin_status',
82
-                'noheader'   => true,
83
-                'capability' => 'ee_edit_checkin',
84
-                'obj_id'     => $reg_id,
85
-            ),
86
-            'event_registrations'      => array(
87
-                'func'       => '_event_registrations_list_table',
88
-                'capability' => 'ee_read_checkins',
89
-            ),
90
-            'registrations_checkin_report' => array(
91
-                'func'       => '_registrations_checkin_report',
92
-                'noheader'   => true,
93
-                'capability' => 'ee_read_registrations',
94
-            ),
95
-        );
96
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
97
-        $new_page_config = array(
98
-            'reports'               => array(
99
-                'nav'           => array(
100
-                    'label' => __('Reports', 'event_espresso'),
101
-                    'order' => 30,
102
-                ),
103
-                'help_tabs'     => array(
104
-                    'registrations_reports_help_tab' => array(
105
-                        'title'    => __('Registration Reports', 'event_espresso'),
106
-                        'filename' => 'registrations_reports',
107
-                    ),
108
-                ),
109
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
110
-                'require_nonce' => false,
111
-            ),
112
-            'event_registrations'   => array(
113
-                'nav'           => array(
114
-                    'label'      => __('Event Check-In', 'event_espresso'),
115
-                    'order'      => 10,
116
-                    'persistent' => true,
117
-                ),
118
-                'help_tabs'     => array(
119
-                    'registrations_event_checkin_help_tab'                       => array(
120
-                        'title'    => __('Registrations Event Check-In', 'event_espresso'),
121
-                        'filename' => 'registrations_event_checkin',
122
-                    ),
123
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
124
-                        'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
125
-                        'filename' => 'registrations_event_checkin_table_column_headings',
126
-                    ),
127
-                    'registrations_event_checkin_filters_help_tab'               => array(
128
-                        'title'    => __('Event Check-In Filters', 'event_espresso'),
129
-                        'filename' => 'registrations_event_checkin_filters',
130
-                    ),
131
-                    'registrations_event_checkin_views_help_tab'                 => array(
132
-                        'title'    => __('Event Check-In Views', 'event_espresso'),
133
-                        'filename' => 'registrations_event_checkin_views',
134
-                    ),
135
-                    'registrations_event_checkin_other_help_tab'                 => array(
136
-                        'title'    => __('Event Check-In Other', 'event_espresso'),
137
-                        'filename' => 'registrations_event_checkin_other',
138
-                    ),
139
-                ),
140
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
141
-                'qtips'         => array('Registration_List_Table_Tips'),
142
-                'list_table'    => 'EE_Event_Registrations_List_Table',
143
-                'metaboxes'     => array(),
144
-                'require_nonce' => false,
145
-            ),
146
-            'registration_checkins' => array(
147
-                'nav'           => array(
148
-                    'label'      => __('Check-In Records', 'event_espresso'),
149
-                    'order'      => 15,
150
-                    'persistent' => false,
151
-                ),
152
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
153
-                //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
154
-                'metaboxes'     => array(),
155
-                'require_nonce' => false,
156
-            ),
157
-        );
158
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
159
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
-    }
162
-
163
-
164
-
165
-    protected function _ajax_hooks()
166
-    {
167
-        parent::_ajax_hooks();
168
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169
-    }
170
-
171
-
172
-
173
-    public function load_scripts_styles()
174
-    {
175
-        parent::load_scripts_styles();
176
-        //if newsletter message type is active then let's add filter and load js for it.
177
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
178
-            //enqueue newsletter js
179
-            wp_enqueue_script(
180
-                'ee-newsletter-trigger',
181
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
182
-                array('ee-dialog'),
183
-                EVENT_ESPRESSO_VERSION,
184
-                true
185
-            );
186
-            wp_enqueue_style(
187
-                'ee-newsletter-trigger-css',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
189
-                array(),
190
-                EVENT_ESPRESSO_VERSION
191
-            );
192
-            //hook in buttons for newsletter message type trigger.
193
-            add_action(
194
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
195
-                array($this, 'add_newsletter_action_buttons'),
196
-                10
197
-            );
198
-        }
199
-    }
200
-
201
-
202
-
203
-    public function load_scripts_styles_reports()
204
-    {
205
-        wp_register_script(
206
-            'ee-reg-reports-js',
207
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
208
-            array('google-charts'),
209
-            EVENT_ESPRESSO_VERSION,
210
-            true
211
-        );
212
-        wp_enqueue_script('ee-reg-reports-js');
213
-        $this->_registration_reports_js_setup();
214
-    }
215
-
216
-
217
-
218
-    protected function _add_screen_options_event_registrations()
219
-    {
220
-        $this->_per_page_screen_option();
221
-    }
222
-
223
-
224
-
225
-    protected function _add_screen_options_registration_checkins()
226
-    {
227
-        $page_title = $this->_admin_page_title;
228
-        $this->_admin_page_title = __('Check-In Records', 'event_espresso');
229
-        $this->_per_page_screen_option();
230
-        $this->_admin_page_title = $page_title;
231
-    }
232
-
233
-
234
-
235
-    protected function _set_list_table_views_event_registrations()
236
-    {
237
-        $this->_views = array(
238
-            'all' => array(
239
-                'slug'        => 'all',
240
-                'label'       => __('All', 'event_espresso'),
241
-                'count'       => 0,
242
-                'bulk_action' => ! isset($this->_req_data['event_id'])
243
-                    ? array()
244
-                    : array(
245
-                        'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
246
-                        //'trash_registrations' => __('Trash Registrations', 'event_espresso')
247
-                    ),
248
-            ),
249
-        );
250
-    }
251
-
252
-
253
-
254
-    protected function _set_list_table_views_registration_checkins()
255
-    {
256
-        $this->_views = array(
257
-            'all' => array(
258
-                'slug'        => 'all',
259
-                'label'       => __('All', 'event_espresso'),
260
-                'count'       => 0,
261
-                'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
262
-            ),
263
-        );
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * callback for ajax action.
270
-     *
271
-     * @since 4.3.0
272
-     * @return void (JSON)
273
-     * @throws \EE_Error
274
-     */
275
-    public function get_newsletter_form_content()
276
-    {
277
-        //do a nonce check cause we're not coming in from an normal route here.
278
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
279
-            $this->_req_data['get_newsletter_form_content_nonce']
280
-        ) : '';
281
-        $nonce_ref = 'get_newsletter_form_content_nonce';
282
-        $this->_verify_nonce($nonce, $nonce_ref);
283
-        //let's get the mtp for the incoming MTP_ ID
284
-        if ( ! isset($this->_req_data['GRP_ID'])) {
285
-            EE_Error::add_error(
286
-                __(
287
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
288
-                    'event_espresso'
289
-                ),
290
-                __FILE__,
291
-                __FUNCTION__,
292
-                __LINE__
293
-            );
294
-            $this->_template_args['success'] = false;
295
-            $this->_template_args['error'] = true;
296
-            $this->_return_json();
297
-        }
298
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
299
-        if ( ! $MTPG instanceof EE_Message_Template_Group) {
300
-            EE_Error::add_error(
301
-                sprintf(
302
-                    __(
303
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
304
-                        'event_espresso'
305
-                    ),
306
-                    $this->_req_data['GRP_ID']
307
-                ),
308
-                __FILE__,
309
-                __FUNCTION__,
310
-                __LINE__
311
-            );
312
-            $this->_template_args['success'] = false;
313
-            $this->_template_args['error'] = true;
314
-            $this->_return_json();
315
-        }
316
-        $MTPs = $MTPG->context_templates();
317
-        $MTPs = $MTPs['attendee'];
318
-        $template_fields = array();
319
-        /** @var EE_Message_Template $MTP */
320
-        foreach ($MTPs as $MTP) {
321
-            $field = $MTP->get('MTP_template_field');
322
-            if ($field === 'content') {
323
-                $content = $MTP->get('MTP_content');
324
-                if ( ! empty($content['newsletter_content'])) {
325
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
326
-                }
327
-                continue;
328
-            }
329
-            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
330
-        }
331
-        $this->_template_args['success'] = true;
332
-        $this->_template_args['error'] = false;
333
-        $this->_template_args['data'] = array(
334
-            'batch_message_from'    => isset($template_fields['from'])
335
-                ? $template_fields['from']
336
-                : '',
337
-            'batch_message_subject' => isset($template_fields['subject'])
338
-                ? $template_fields['subject']
339
-                : '',
340
-            'batch_message_content' => isset($template_fields['newsletter_content'])
341
-                ? $template_fields['newsletter_content']
342
-                : '',
343
-        );
344
-        $this->_return_json();
345
-    }
346
-
347
-
348
-
349
-    /**
350
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
351
-     *
352
-     * @since 4.3.0
353
-     * @param EE_Admin_List_Table $list_table
354
-     * @return void
355
-     */
356
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
357
-    {
358
-        if ( ! EE_Registry::instance()->CAP->current_user_can(
359
-            'ee_send_message',
360
-            'espresso_registrations_newsletter_selected_send'
361
-        )
362
-        ) {
363
-            return;
364
-        }
365
-        $routes_to_add_to = array(
366
-            'contact_list',
367
-            'event_registrations',
368
-            'default',
369
-        );
370
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
371
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
372
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
373
-            ) {
374
-                echo '';
375
-            } else {
376
-                $button_text = sprintf(
377
-                    __('Send Batch Message (%s selected)', 'event_espresso'),
378
-                    '<span class="send-selected-newsletter-count">0</span>'
379
-                );
380
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
381
-                     . $button_text
382
-                     . '</button>';
383
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
384
-            }
385
-        }
386
-    }
387
-
388
-
389
-
390
-    public function newsletter_send_form_skeleton()
391
-    {
392
-        $list_table = $this->_list_table_object;
393
-        $codes = array();
394
-        //need to templates for the newsletter message type for the template selector.
395
-        $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
396
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
397
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
398
-        );
399
-        foreach ($mtps as $mtp) {
400
-            $name = $mtp->name();
401
-            $values[] = array(
402
-                'text' => empty($name) ? __('Global', 'event_espresso') : $name,
403
-                'id'   => $mtp->ID(),
404
-            );
405
-        }
406
-        //need to get a list of shortcodes that are available for the newsletter message type.
407
-        $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
408
-        foreach ($shortcodes as $field => $shortcode_array) {
409
-            $codes[$field] = implode(', ', array_keys($shortcode_array));
410
-        }
411
-        $shortcodes = $codes;
412
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
413
-        $form_template_args = array(
414
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415
-            'form_route'        => 'newsletter_selected_send',
416
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
417
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
418
-            'redirect_back_to'  => $this->_req_action,
419
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
420
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
421
-            'shortcodes'        => $shortcodes,
422
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
423
-        );
424
-        EEH_Template::display_template($form_template, $form_template_args);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Handles sending selected registrations/contacts a newsletter.
431
-     *
432
-     * @since  4.3.0
433
-     * @return void
434
-     * @throws \EE_Error
435
-     */
436
-    protected function _newsletter_selected_send()
437
-    {
438
-        $success = true;
439
-        //first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
440
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
441
-            EE_Error::add_error(
442
-                __(
443
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
444
-                    'event_espresso'
445
-                ),
446
-                __FILE__,
447
-                __FUNCTION__,
448
-                __LINE__
449
-            );
450
-            $success = false;
451
-        }
452
-        if ($success) {
453
-            //update Message template in case there are any changes
454
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
455
-                $this->_req_data['newsletter_mtp_selected']
456
-            );
457
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
458
-                ? $Message_Template_Group->context_templates()
459
-                : array();
460
-            if (empty($Message_Templates)) {
461
-                EE_Error::add_error(
462
-                    __(
463
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
464
-                        'event_espresso'
465
-                    ),
466
-                    __FILE__,
467
-                    __FUNCTION__,
468
-                    __LINE__
469
-                );
470
-            }
471
-            //let's just update the specific fields
472
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
473
-                if ($Message_Template instanceof EE_Message_Template) {
474
-                    $field = $Message_Template->get('MTP_template_field');
475
-                    $content = $Message_Template->get('MTP_content');
476
-                    $new_content = $content;
477
-                    switch ($field) {
478
-                        case 'from' :
479
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
480
-                                ? $this->_req_data['batch_message']['from']
481
-                                : $content;
482
-                            break;
483
-                        case 'subject' :
484
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
485
-                                ? $this->_req_data['batch_message']['subject']
486
-                                : $content;
487
-                            break;
488
-                        case 'content' :
489
-                            $new_content = $content;
490
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
491
-                                ? $this->_req_data['batch_message']['content']
492
-                                : $content['newsletter_content'];
493
-                            break;
494
-                        default :
495
-                            //continue the foreach loop, we don't want to set $new_content nor save.
496
-                            continue 2;
497
-                    }
498
-                    $Message_Template->set('MTP_content', $new_content);
499
-                    $Message_Template->save();
500
-                }
501
-            }
502
-            //great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
503
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
504
-                ? $this->_req_data['batch_message']['id_type']
505
-                : 'registration';
506
-            //id_type will affect how we assemble the ids.
507
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
508
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
509
-                : array();
510
-            $registrations_used_for_contact_data = array();
511
-            //using switch because eventually we'll have other contexts that will be used for generating messages.
512
-            switch ($id_type) {
513
-                case 'registration' :
514
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
515
-                        array(
516
-                            array(
517
-                                'REG_ID' => array('IN', $ids),
518
-                            ),
519
-                        )
520
-                    );
521
-                    break;
522
-                case 'contact' :
523
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
524
-                                                                           ->get_latest_registration_for_each_of_given_contacts($ids);
525
-                    break;
526
-            }
527
-            do_action(
528
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
529
-                $registrations_used_for_contact_data,
530
-                $Message_Template_Group->ID()
531
-            );
532
-            //kept for backward compat, internally we no longer use this action.
533
-            //@deprecated 4.8.36.rc.002
534
-            $contacts = $id_type === 'registration'
535
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
536
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
537
-            do_action(
538
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
539
-                $contacts,
540
-                $Message_Template_Group->ID()
541
-            );
542
-        }
543
-        $query_args = array(
544
-            'action' => ! empty($this->_req_data['redirect_back_to'])
545
-                ? $this->_req_data['redirect_back_to']
546
-                : 'default',
547
-        );
548
-        $this->_redirect_after_action(false, '', '', $query_args, true);
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
555
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
556
-     */
557
-    protected function _registration_reports_js_setup()
558
-    {
559
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
560
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     *        generates Business Reports regarding Registrations
567
-     *
568
-     * @access protected
569
-     * @return void
570
-     */
571
-    protected function _registration_reports()
572
-    {
573
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
574
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
575
-            $template_path,
576
-            $this->_reports_template_data,
577
-            true
578
-        );
579
-        // the final template wrapper
580
-        $this->display_admin_page_with_no_sidebar();
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Generates Business Report showing total registrations per day.
587
-     *
588
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
589
-     * @return string
590
-     */
591
-    private function _registrations_per_day_report($period = '-1 month')
592
-    {
593
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
594
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
-        $results = (array)$results;
596
-        $regs = array();
597
-        $subtitle = '';
598
-        if ($results) {
599
-            $column_titles = array();
600
-            $tracker = 0;
601
-            foreach ($results as $result) {
602
-                $report_column_values = array();
603
-                foreach ($result as $property_name => $property_value) {
604
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
605
-                        : (int)$property_value;
606
-                    $report_column_values[] = $property_value;
607
-                    if ($tracker === 0) {
608
-                        if ($property_name === 'Registration_REG_date') {
609
-                            $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
610
-                        } else {
611
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
612
-                        }
613
-                    }
614
-                }
615
-                $tracker++;
616
-                $regs[] = $report_column_values;
617
-            }
618
-            //make sure the column_titles is pushed to the beginning of the array
619
-            array_unshift($regs, $column_titles);
620
-            //setup the date range.
621
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
623
-            $ending_date = new DateTime("now", $DateTimeZone);
624
-            $subtitle = sprintf(
625
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
626
-                $beginning_date->format('Y-m-d'),
627
-                $ending_date->format('Y-m-d')
628
-            );
629
-        }
630
-        $report_title = __('Total Registrations per Day', 'event_espresso');
631
-        $report_params = array(
632
-            'title'     => $report_title,
633
-            'subtitle'  => $subtitle,
634
-            'id'        => $report_ID,
635
-            'regs'      => $regs,
636
-            'noResults' => empty($regs),
637
-            'noRegsMsg' => sprintf(
638
-                __(
639
-                    '%sThere are currently no registration records in the last month for this report.%s',
640
-                    'event_espresso'
641
-                ),
642
-                '<h2>' . $report_title . '</h2><p>',
643
-                '</p>'
644
-            ),
645
-        );
646
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
647
-        return $report_ID;
648
-    }
649
-
650
-
651
-
652
-    /**
653
-     * Generates Business Report showing total registrations per event.
654
-     *
655
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
656
-     * @return string
657
-     */
658
-    private function _registrations_per_event_report($period = '-1 month')
659
-    {
660
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
661
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
-        $results = (array)$results;
663
-        $regs = array();
664
-        $subtitle = '';
665
-        if ($results) {
666
-            $column_titles = array();
667
-            $tracker = 0;
668
-            foreach ($results as $result) {
669
-                $report_column_values = array();
670
-                foreach ($result as $property_name => $property_value) {
671
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
672
-                        $property_value,
673
-                        4,
674
-                        '...'
675
-                    ) : (int)$property_value;
676
-                    $report_column_values[] = $property_value;
677
-                    if ($tracker === 0) {
678
-                        if ($property_name === 'Registration_Event') {
679
-                            $column_titles[] = __('Event', 'event_espresso');
680
-                        } else {
681
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
682
-                        }
683
-                    }
684
-                }
685
-                $tracker++;
686
-                $regs[] = $report_column_values;
687
-            }
688
-            //make sure the column_titles is pushed to the beginning of the array
689
-            array_unshift($regs, $column_titles);
690
-            //setup the date range.
691
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
693
-            $ending_date = new DateTime("now", $DateTimeZone);
694
-            $subtitle = sprintf(
695
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
696
-                $beginning_date->format('Y-m-d'),
697
-                $ending_date->format('Y-m-d')
698
-            );
699
-        }
700
-        $report_title = __('Total Registrations per Event', 'event_espresso');
701
-        $report_params = array(
702
-            'title'     => $report_title,
703
-            'subtitle'  => $subtitle,
704
-            'id'        => $report_ID,
705
-            'regs'      => $regs,
706
-            'noResults' => empty($regs),
707
-            'noRegsMsg' => sprintf(
708
-                __(
709
-                    '%sThere are currently no registration records in the last month for this report.%s',
710
-                    'event_espresso'
711
-                ),
712
-                '<h2>' . $report_title . '</h2><p>',
713
-                '</p>'
714
-            ),
715
-        );
716
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
717
-        return $report_ID;
718
-    }
719
-
720
-
721
-
722
-    /**
723
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
724
-     *
725
-     * @access protected
726
-     * @return void
727
-     * @throws \EE_Error
728
-     */
729
-    protected function _registration_checkin_list_table()
730
-    {
731
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
732
-        $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
733
-        /** @var EE_Registration $registration */
734
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
735
-        $attendee = $registration->attendee();
736
-        $this->_admin_page_title .= $this->get_action_link_or_button(
737
-            'new_registration',
738
-            'add-registrant',
739
-            array('event_id' => $registration->event_ID()),
740
-            'add-new-h2'
741
-        );
742
-        $legend_items = array(
743
-            'checkin'  => array(
744
-                'class' => 'ee-icon ee-icon-check-in',
745
-                'desc'  => __('This indicates the attendee has been checked in', 'event_espresso'),
746
-            ),
747
-            'checkout' => array(
748
-                'class' => 'ee-icon ee-icon-check-out',
749
-                'desc'  => __('This indicates the attendee has been checked out', 'event_espresso'),
750
-            ),
751
-        );
752
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
753
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
754
-        /** @var EE_Datetime $datetime */
755
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
756
-        $datetime_label = '';
757
-        if ($datetime instanceof EE_Datetime) {
758
-            $datetime_label = $datetime->get_dtt_display_name(true);
759
-            $datetime_label .= ! empty($datetime_label)
760
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
761
-                : $datetime->get_dtt_display_name();
762
-        }
763
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
764
-            ? EE_Admin_Page::add_query_args_and_nonce(
765
-                array(
766
-                    'action'   => 'event_registrations',
767
-                    'event_id' => $registration->event_ID(),
768
-                    'DTT_ID'   => $dtt_id,
769
-                ),
770
-                $this->_admin_base_url
771
-            )
772
-            : '';
773
-        $datetime_link = ! empty($datetime_link)
774
-            ? '<a href="' . $datetime_link . '">'
775
-              . '<span id="checkin-dtt">'
776
-              . $datetime_label
777
-              . '</span></a>'
778
-            : $datetime_label;
779
-        $attendee_name = $attendee instanceof EE_Attendee
780
-            ? $attendee->full_name()
781
-            : '';
782
-        $attendee_link = $attendee instanceof EE_Attendee
783
-            ? $attendee->get_admin_details_link()
784
-            : '';
785
-        $attendee_link = ! empty($attendee_link)
786
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
787
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
788
-              . '<span id="checkin-attendee-name">'
789
-              . $attendee_name
790
-              . '</span></a>'
791
-            : '';
792
-        $event_link = $registration->event() instanceof EE_Event
793
-            ? $registration->event()->get_admin_details_link()
794
-            : '';
795
-        $event_link = ! empty($event_link)
796
-            ? '<a href="' . $event_link . '"'
797
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
798
-              . '<span id="checkin-event-name">'
799
-              . $registration->event_name()
800
-              . '</span>'
801
-              . '</a>'
802
-            : '';
803
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
-            ? '<h2>' . sprintf(
805
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806
-                $attendee_link,
807
-                $datetime_link,
808
-                $event_link
809
-            ) . '</h2>'
810
-            : '';
811
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
813
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
815
-        $this->display_admin_list_table_page_with_no_sidebar();
816
-    }
817
-
818
-
819
-
820
-    /**
821
-     * toggle the Check-in status for the given registration (coming from ajax)
822
-     *
823
-     * @return void (JSON)
824
-     */
825
-    public function toggle_checkin_status()
826
-    {
827
-        //first make sure we have the necessary data
828
-        if ( ! isset($this->_req_data['_regid'])) {
829
-            EE_Error::add_error(
830
-                __(
831
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
832
-                    'event_espresso'
833
-                ),
834
-                __FILE__,
835
-                __FUNCTION__,
836
-                __LINE__
837
-            );
838
-            $this->_template_args['success'] = false;
839
-            $this->_template_args['error'] = true;
840
-            $this->_return_json();
841
-        };
842
-        //do a nonce check cause we're not coming in from an normal route here.
843
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
844
-            : '';
845
-        $nonce_ref = 'checkin_nonce';
846
-        $this->_verify_nonce($nonce, $nonce_ref);
847
-        //beautiful! Made it this far so let's get the status.
848
-        $new_status = $this->_toggle_checkin_status();
849
-        //setup new class to return via ajax
850
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'
851
-                                                      . $new_status;
852
-        $this->_template_args['success'] = true;
853
-        $this->_return_json();
854
-    }
855
-
856
-
857
-
858
-    /**
859
-     * handles toggling the checkin status for the registration,
860
-     *
861
-     * @access protected
862
-     * @return int|void
863
-     */
864
-    protected function _toggle_checkin_status()
865
-    {
866
-        //first let's get the query args out of the way for the redirect
867
-        $query_args = array(
868
-            'action'   => 'event_registrations',
869
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
870
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
871
-        );
872
-        $new_status = false;
873
-        // bulk action check in toggle
874
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
-            // cycle thru checkboxes
876
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
877
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
878
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
879
-            }
880
-        } elseif (isset($this->_req_data['_regid'])) {
881
-            //coming from ajax request
882
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
883
-            $query_args['DTT_ID'] = $DTT_ID;
884
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
885
-        } else {
886
-            EE_Error::add_error(
887
-                __('Missing some required data to toggle the Check-in', 'event_espresso'),
888
-                __FILE__,
889
-                __FUNCTION__,
890
-                __LINE__
891
-            );
892
-        }
893
-        if (defined('DOING_AJAX')) {
894
-            return $new_status;
895
-        }
896
-        $this->_redirect_after_action(false, '', '', $query_args, true);
897
-    }
898
-
899
-
900
-
901
-    /**
902
-     * This is toggles a single Check-in for the given registration and datetime.
903
-     *
904
-     * @param  int $REG_ID The registration we're toggling
905
-     * @param  int $DTT_ID The datetime we're toggling
906
-     * @return int            The new status toggled to.
907
-     * @throws \EE_Error
908
-     */
909
-    private function _toggle_checkin($REG_ID, $DTT_ID)
910
-    {
911
-        /** @var EE_Registration $REG */
912
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
913
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
914
-        if ($new_status !== false) {
915
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
916
-        } else {
917
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
918
-            $new_status = false;
919
-        }
920
-        return $new_status;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * Takes care of deleting multiple EE_Checkin table rows
927
-     *
928
-     * @access protected
929
-     * @return void
930
-     * @throws \EE_Error
931
-     */
932
-    protected function _delete_checkin_rows()
933
-    {
934
-        $query_args = array(
935
-            'action' => 'registration_checkins',
936
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
937
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
938
-        );
939
-        $errors = 0;
940
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
941
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
942
-                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
943
-                    $errors++;
944
-                }
945
-            }
946
-        } else {
947
-            EE_Error::add_error(
948
-                __(
949
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
950
-                    'event_espresso'
951
-                ),
952
-                __FILE__,
953
-                __FUNCTION__,
954
-                __LINE__
955
-            );
956
-            $this->_redirect_after_action(false, '', '', $query_args, true);
957
-        }
958
-        if ($errors > 0) {
959
-            EE_Error::add_error(
960
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
961
-                __FILE__,
962
-                __FUNCTION__,
963
-                __LINE__
964
-            );
965
-        } else {
966
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
967
-        }
968
-        $this->_redirect_after_action(false, '', '', $query_args, true);
969
-    }
970
-
971
-
972
-
973
-    /**
974
-     * Deletes a single EE_Checkin row
975
-     *
976
-     * @return void
977
-     * @throws \EE_Error
978
-     */
979
-    protected function _delete_checkin_row()
980
-    {
981
-        $query_args = array(
982
-            'action' => 'registration_checkins',
983
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
984
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
985
-        );
986
-        if ( ! empty($this->_req_data['CHK_ID'])) {
987
-            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
988
-                EE_Error::add_error(
989
-                    __('Something went wrong and this check-in record was not deleted', 'event_espresso'),
990
-                    __FILE__,
991
-                    __FUNCTION__,
992
-                    __LINE__
993
-                );
994
-            } else {
995
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
996
-            }
997
-        } else {
998
-            EE_Error::add_error(
999
-                __(
1000
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1001
-                    'event_espresso'
1002
-                ),
1003
-                __FILE__,
1004
-                __FUNCTION__,
1005
-                __LINE__
1006
-            );
1007
-        }
1008
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     *        generates HTML for the Event Registrations List Table
1015
-     *
1016
-     * @access protected
1017
-     * @return void
1018
-     * @throws \EE_Error
1019
-     */
1020
-    protected function _event_registrations_list_table()
1021
-    {
1022
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1023
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1024
-            ? $this->get_action_link_or_button(
1025
-                'new_registration',
1026
-                'add-registrant',
1027
-                array('event_id' => $this->_req_data['event_id']),
1028
-                'add-new-h2',
1029
-                '',
1030
-                false
1031
-            )
1032
-            : '';
1033
-        $legend_items = array(
1034
-            'star-icon'        => array(
1035
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
-                'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1037
-            ),
1038
-            'checkin'          => array(
1039
-                'class' => 'ee-icon ee-icon-check-in',
1040
-                'desc'  => __('This Registrant has been Checked In', 'event_espresso'),
1041
-            ),
1042
-            'checkout'         => array(
1043
-                'class' => 'ee-icon ee-icon-check-out',
1044
-                'desc'  => __('This Registrant has been Checked Out', 'event_espresso'),
1045
-            ),
1046
-            'nocheckinrecord'  => array(
1047
-                'class' => 'dashicons dashicons-no',
1048
-                'desc'  => __('No Check-in Record has been Created for this Registrant', 'event_espresso'),
1049
-            ),
1050
-            'view_details'     => array(
1051
-                'class' => 'dashicons dashicons-search',
1052
-                'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053
-            ),
1054
-            'approved_status'  => array(
1055
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1056
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057
-            ),
1058
-            'cancelled_status' => array(
1059
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1060
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061
-            ),
1062
-            'declined_status'  => array(
1063
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1064
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065
-            ),
1066
-            'not_approved'     => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069
-            ),
1070
-            'pending_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073
-            ),
1074
-            'wait_list'        => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077
-            ),
1078
-        );
1079
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081
-        $this->_template_args['before_list_table'] = ! empty($event_id)
1082
-            ? '<h2>' . sprintf(
1083
-                __('Viewing Registrations for Event: %s', 'event_espresso'),
1084
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
-            ) . '</h2>'
1086
-            : '';
1087
-        //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088
-        /** @var EE_Event $event */
1089
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1090
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1091
-        $datetime = null;
1092
-        if ($event instanceof EE_Event) {
1093
-            $datetimes_on_event = $event->datetimes();
1094
-            if (count($datetimes_on_event) === 1) {
1095
-                $datetime = reset($datetimes_on_event);
1096
-            }
1097
-        }
1098
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1099
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1100
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1101
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103
-            $this->_template_args['before_list_table'] .= $datetime->name();
1104
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1105
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1106
-        }
1107
-        //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1108
-        //represents
1109
-        if ( ! $datetime instanceof EE_Datetime) {
1110
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1111
-                                                          . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1112
-                    'event_espresso')
1113
-                                                          . '</p>';
1114
-        }
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-    /**
1119
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1120
-     * conditions)
1121
-     *
1122
-     * @return void ends the request by a redirect or download
1123
-     */
1124
-    public function _registrations_checkin_report()
1125
-    {
1126
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1127
-    }
1128
-
1129
-    /**
1130
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1131
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1132
-     *
1133
-     * @param array     $request
1134
-     * @param int  $per_page
1135
-     * @param bool $count
1136
-     * @return array
1137
-     */
1138
-    protected function _get_checkin_query_params_from_request(
1139
-        $request,
1140
-        $per_page = 10,
1141
-        $count = false
1142
-    ) {
1143
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1144
-        //unlike the regular registrations list table,
1145
-        $status_ids_array = apply_filters(
1146
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1147
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1148
-        );
1149
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1150
-        return $query_params;
1151
-    }
1152
-
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * Gets registrations for an event
1158
-     *
1159
-     * @param int    $per_page
1160
-     * @param bool   $count whether to return count or data.
1161
-     * @param bool   $trash
1162
-     * @param string $orderby
1163
-     * @return EE_Registration[]|int
1164
-     * @throws \EE_Error
1165
-     */
1166
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1167
-    {
1168
-        //normalize some request params that get setup by the parent `get_registrations` method.
1169
-        $request = $this->_req_data;
1170
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
-        if($trash){
1173
-            $request['status'] = 'trash';
1174
-        }
1175
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1176
-        /**
1177
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1179
-         * @see EEM_Base::get_all()
1180
-         */
1181
-        $query_params['group_by'] = '';
1182
-
1183
-        return $count
1184
-            ? EEM_Registration::instance()->count($query_params)
1185
-            /** @type EE_Registration[] */
1186
-            : EEM_Registration::instance()->get_all($query_params);
1187
-    }
20
+	/**
21
+	 * This is used to hold the reports template data which is setup early in the request.
22
+	 *
23
+	 * @type array
24
+	 */
25
+	protected $_reports_template_data = array();
26
+
27
+
28
+
29
+	/**
30
+	 * Extend_Registrations_Admin_Page constructor.
31
+	 *
32
+	 * @param bool $routing
33
+	 */
34
+	public function __construct($routing = true)
35
+	{
36
+		parent::__construct($routing);
37
+		if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
+		}
42
+	}
43
+
44
+
45
+
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		// $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
+		// $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
54
+		// 	? $this->_req_data['post'] : $att_id;
55
+		$new_page_routes = array(
56
+			'reports'                  => array(
57
+				'func'       => '_registration_reports',
58
+				'capability' => 'ee_read_registrations',
59
+			),
60
+			'registration_checkins'    => array(
61
+				'func'       => '_registration_checkin_list_table',
62
+				'capability' => 'ee_read_checkins',
63
+			),
64
+			'newsletter_selected_send' => array(
65
+				'func'       => '_newsletter_selected_send',
66
+				'noheader'   => true,
67
+				'capability' => 'ee_send_message',
68
+			),
69
+			'delete_checkin_rows'      => array(
70
+				'func'       => '_delete_checkin_rows',
71
+				'noheader'   => true,
72
+				'capability' => 'ee_delete_checkins',
73
+			),
74
+			'delete_checkin_row'       => array(
75
+				'func'       => '_delete_checkin_row',
76
+				'noheader'   => true,
77
+				'capability' => 'ee_delete_checkin',
78
+				'obj_id'     => $reg_id,
79
+			),
80
+			'toggle_checkin_status'    => array(
81
+				'func'       => '_toggle_checkin_status',
82
+				'noheader'   => true,
83
+				'capability' => 'ee_edit_checkin',
84
+				'obj_id'     => $reg_id,
85
+			),
86
+			'event_registrations'      => array(
87
+				'func'       => '_event_registrations_list_table',
88
+				'capability' => 'ee_read_checkins',
89
+			),
90
+			'registrations_checkin_report' => array(
91
+				'func'       => '_registrations_checkin_report',
92
+				'noheader'   => true,
93
+				'capability' => 'ee_read_registrations',
94
+			),
95
+		);
96
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
97
+		$new_page_config = array(
98
+			'reports'               => array(
99
+				'nav'           => array(
100
+					'label' => __('Reports', 'event_espresso'),
101
+					'order' => 30,
102
+				),
103
+				'help_tabs'     => array(
104
+					'registrations_reports_help_tab' => array(
105
+						'title'    => __('Registration Reports', 'event_espresso'),
106
+						'filename' => 'registrations_reports',
107
+					),
108
+				),
109
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
110
+				'require_nonce' => false,
111
+			),
112
+			'event_registrations'   => array(
113
+				'nav'           => array(
114
+					'label'      => __('Event Check-In', 'event_espresso'),
115
+					'order'      => 10,
116
+					'persistent' => true,
117
+				),
118
+				'help_tabs'     => array(
119
+					'registrations_event_checkin_help_tab'                       => array(
120
+						'title'    => __('Registrations Event Check-In', 'event_espresso'),
121
+						'filename' => 'registrations_event_checkin',
122
+					),
123
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
124
+						'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
125
+						'filename' => 'registrations_event_checkin_table_column_headings',
126
+					),
127
+					'registrations_event_checkin_filters_help_tab'               => array(
128
+						'title'    => __('Event Check-In Filters', 'event_espresso'),
129
+						'filename' => 'registrations_event_checkin_filters',
130
+					),
131
+					'registrations_event_checkin_views_help_tab'                 => array(
132
+						'title'    => __('Event Check-In Views', 'event_espresso'),
133
+						'filename' => 'registrations_event_checkin_views',
134
+					),
135
+					'registrations_event_checkin_other_help_tab'                 => array(
136
+						'title'    => __('Event Check-In Other', 'event_espresso'),
137
+						'filename' => 'registrations_event_checkin_other',
138
+					),
139
+				),
140
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
141
+				'qtips'         => array('Registration_List_Table_Tips'),
142
+				'list_table'    => 'EE_Event_Registrations_List_Table',
143
+				'metaboxes'     => array(),
144
+				'require_nonce' => false,
145
+			),
146
+			'registration_checkins' => array(
147
+				'nav'           => array(
148
+					'label'      => __('Check-In Records', 'event_espresso'),
149
+					'order'      => 15,
150
+					'persistent' => false,
151
+				),
152
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
153
+				//'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
154
+				'metaboxes'     => array(),
155
+				'require_nonce' => false,
156
+			),
157
+		);
158
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
159
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
+	}
162
+
163
+
164
+
165
+	protected function _ajax_hooks()
166
+	{
167
+		parent::_ajax_hooks();
168
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169
+	}
170
+
171
+
172
+
173
+	public function load_scripts_styles()
174
+	{
175
+		parent::load_scripts_styles();
176
+		//if newsletter message type is active then let's add filter and load js for it.
177
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
178
+			//enqueue newsletter js
179
+			wp_enqueue_script(
180
+				'ee-newsletter-trigger',
181
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
182
+				array('ee-dialog'),
183
+				EVENT_ESPRESSO_VERSION,
184
+				true
185
+			);
186
+			wp_enqueue_style(
187
+				'ee-newsletter-trigger-css',
188
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
189
+				array(),
190
+				EVENT_ESPRESSO_VERSION
191
+			);
192
+			//hook in buttons for newsletter message type trigger.
193
+			add_action(
194
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
195
+				array($this, 'add_newsletter_action_buttons'),
196
+				10
197
+			);
198
+		}
199
+	}
200
+
201
+
202
+
203
+	public function load_scripts_styles_reports()
204
+	{
205
+		wp_register_script(
206
+			'ee-reg-reports-js',
207
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
208
+			array('google-charts'),
209
+			EVENT_ESPRESSO_VERSION,
210
+			true
211
+		);
212
+		wp_enqueue_script('ee-reg-reports-js');
213
+		$this->_registration_reports_js_setup();
214
+	}
215
+
216
+
217
+
218
+	protected function _add_screen_options_event_registrations()
219
+	{
220
+		$this->_per_page_screen_option();
221
+	}
222
+
223
+
224
+
225
+	protected function _add_screen_options_registration_checkins()
226
+	{
227
+		$page_title = $this->_admin_page_title;
228
+		$this->_admin_page_title = __('Check-In Records', 'event_espresso');
229
+		$this->_per_page_screen_option();
230
+		$this->_admin_page_title = $page_title;
231
+	}
232
+
233
+
234
+
235
+	protected function _set_list_table_views_event_registrations()
236
+	{
237
+		$this->_views = array(
238
+			'all' => array(
239
+				'slug'        => 'all',
240
+				'label'       => __('All', 'event_espresso'),
241
+				'count'       => 0,
242
+				'bulk_action' => ! isset($this->_req_data['event_id'])
243
+					? array()
244
+					: array(
245
+						'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
246
+						//'trash_registrations' => __('Trash Registrations', 'event_espresso')
247
+					),
248
+			),
249
+		);
250
+	}
251
+
252
+
253
+
254
+	protected function _set_list_table_views_registration_checkins()
255
+	{
256
+		$this->_views = array(
257
+			'all' => array(
258
+				'slug'        => 'all',
259
+				'label'       => __('All', 'event_espresso'),
260
+				'count'       => 0,
261
+				'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
262
+			),
263
+		);
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * callback for ajax action.
270
+	 *
271
+	 * @since 4.3.0
272
+	 * @return void (JSON)
273
+	 * @throws \EE_Error
274
+	 */
275
+	public function get_newsletter_form_content()
276
+	{
277
+		//do a nonce check cause we're not coming in from an normal route here.
278
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
279
+			$this->_req_data['get_newsletter_form_content_nonce']
280
+		) : '';
281
+		$nonce_ref = 'get_newsletter_form_content_nonce';
282
+		$this->_verify_nonce($nonce, $nonce_ref);
283
+		//let's get the mtp for the incoming MTP_ ID
284
+		if ( ! isset($this->_req_data['GRP_ID'])) {
285
+			EE_Error::add_error(
286
+				__(
287
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
288
+					'event_espresso'
289
+				),
290
+				__FILE__,
291
+				__FUNCTION__,
292
+				__LINE__
293
+			);
294
+			$this->_template_args['success'] = false;
295
+			$this->_template_args['error'] = true;
296
+			$this->_return_json();
297
+		}
298
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
299
+		if ( ! $MTPG instanceof EE_Message_Template_Group) {
300
+			EE_Error::add_error(
301
+				sprintf(
302
+					__(
303
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
304
+						'event_espresso'
305
+					),
306
+					$this->_req_data['GRP_ID']
307
+				),
308
+				__FILE__,
309
+				__FUNCTION__,
310
+				__LINE__
311
+			);
312
+			$this->_template_args['success'] = false;
313
+			$this->_template_args['error'] = true;
314
+			$this->_return_json();
315
+		}
316
+		$MTPs = $MTPG->context_templates();
317
+		$MTPs = $MTPs['attendee'];
318
+		$template_fields = array();
319
+		/** @var EE_Message_Template $MTP */
320
+		foreach ($MTPs as $MTP) {
321
+			$field = $MTP->get('MTP_template_field');
322
+			if ($field === 'content') {
323
+				$content = $MTP->get('MTP_content');
324
+				if ( ! empty($content['newsletter_content'])) {
325
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
326
+				}
327
+				continue;
328
+			}
329
+			$template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
330
+		}
331
+		$this->_template_args['success'] = true;
332
+		$this->_template_args['error'] = false;
333
+		$this->_template_args['data'] = array(
334
+			'batch_message_from'    => isset($template_fields['from'])
335
+				? $template_fields['from']
336
+				: '',
337
+			'batch_message_subject' => isset($template_fields['subject'])
338
+				? $template_fields['subject']
339
+				: '',
340
+			'batch_message_content' => isset($template_fields['newsletter_content'])
341
+				? $template_fields['newsletter_content']
342
+				: '',
343
+		);
344
+		$this->_return_json();
345
+	}
346
+
347
+
348
+
349
+	/**
350
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
351
+	 *
352
+	 * @since 4.3.0
353
+	 * @param EE_Admin_List_Table $list_table
354
+	 * @return void
355
+	 */
356
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
357
+	{
358
+		if ( ! EE_Registry::instance()->CAP->current_user_can(
359
+			'ee_send_message',
360
+			'espresso_registrations_newsletter_selected_send'
361
+		)
362
+		) {
363
+			return;
364
+		}
365
+		$routes_to_add_to = array(
366
+			'contact_list',
367
+			'event_registrations',
368
+			'default',
369
+		);
370
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
371
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
372
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
373
+			) {
374
+				echo '';
375
+			} else {
376
+				$button_text = sprintf(
377
+					__('Send Batch Message (%s selected)', 'event_espresso'),
378
+					'<span class="send-selected-newsletter-count">0</span>'
379
+				);
380
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
381
+					 . $button_text
382
+					 . '</button>';
383
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
384
+			}
385
+		}
386
+	}
387
+
388
+
389
+
390
+	public function newsletter_send_form_skeleton()
391
+	{
392
+		$list_table = $this->_list_table_object;
393
+		$codes = array();
394
+		//need to templates for the newsletter message type for the template selector.
395
+		$values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
396
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
397
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
398
+		);
399
+		foreach ($mtps as $mtp) {
400
+			$name = $mtp->name();
401
+			$values[] = array(
402
+				'text' => empty($name) ? __('Global', 'event_espresso') : $name,
403
+				'id'   => $mtp->ID(),
404
+			);
405
+		}
406
+		//need to get a list of shortcodes that are available for the newsletter message type.
407
+		$shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
408
+		foreach ($shortcodes as $field => $shortcode_array) {
409
+			$codes[$field] = implode(', ', array_keys($shortcode_array));
410
+		}
411
+		$shortcodes = $codes;
412
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
413
+		$form_template_args = array(
414
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415
+			'form_route'        => 'newsletter_selected_send',
416
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
417
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
418
+			'redirect_back_to'  => $this->_req_action,
419
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
420
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
421
+			'shortcodes'        => $shortcodes,
422
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
423
+		);
424
+		EEH_Template::display_template($form_template, $form_template_args);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Handles sending selected registrations/contacts a newsletter.
431
+	 *
432
+	 * @since  4.3.0
433
+	 * @return void
434
+	 * @throws \EE_Error
435
+	 */
436
+	protected function _newsletter_selected_send()
437
+	{
438
+		$success = true;
439
+		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
440
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
441
+			EE_Error::add_error(
442
+				__(
443
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
444
+					'event_espresso'
445
+				),
446
+				__FILE__,
447
+				__FUNCTION__,
448
+				__LINE__
449
+			);
450
+			$success = false;
451
+		}
452
+		if ($success) {
453
+			//update Message template in case there are any changes
454
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
455
+				$this->_req_data['newsletter_mtp_selected']
456
+			);
457
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
458
+				? $Message_Template_Group->context_templates()
459
+				: array();
460
+			if (empty($Message_Templates)) {
461
+				EE_Error::add_error(
462
+					__(
463
+						'Unable to retrieve message template fields from the db. Messages not sent.',
464
+						'event_espresso'
465
+					),
466
+					__FILE__,
467
+					__FUNCTION__,
468
+					__LINE__
469
+				);
470
+			}
471
+			//let's just update the specific fields
472
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
473
+				if ($Message_Template instanceof EE_Message_Template) {
474
+					$field = $Message_Template->get('MTP_template_field');
475
+					$content = $Message_Template->get('MTP_content');
476
+					$new_content = $content;
477
+					switch ($field) {
478
+						case 'from' :
479
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
480
+								? $this->_req_data['batch_message']['from']
481
+								: $content;
482
+							break;
483
+						case 'subject' :
484
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
485
+								? $this->_req_data['batch_message']['subject']
486
+								: $content;
487
+							break;
488
+						case 'content' :
489
+							$new_content = $content;
490
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
491
+								? $this->_req_data['batch_message']['content']
492
+								: $content['newsletter_content'];
493
+							break;
494
+						default :
495
+							//continue the foreach loop, we don't want to set $new_content nor save.
496
+							continue 2;
497
+					}
498
+					$Message_Template->set('MTP_content', $new_content);
499
+					$Message_Template->save();
500
+				}
501
+			}
502
+			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
503
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
504
+				? $this->_req_data['batch_message']['id_type']
505
+				: 'registration';
506
+			//id_type will affect how we assemble the ids.
507
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
508
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
509
+				: array();
510
+			$registrations_used_for_contact_data = array();
511
+			//using switch because eventually we'll have other contexts that will be used for generating messages.
512
+			switch ($id_type) {
513
+				case 'registration' :
514
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
515
+						array(
516
+							array(
517
+								'REG_ID' => array('IN', $ids),
518
+							),
519
+						)
520
+					);
521
+					break;
522
+				case 'contact' :
523
+					$registrations_used_for_contact_data = EEM_Registration::instance()
524
+																		   ->get_latest_registration_for_each_of_given_contacts($ids);
525
+					break;
526
+			}
527
+			do_action(
528
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
529
+				$registrations_used_for_contact_data,
530
+				$Message_Template_Group->ID()
531
+			);
532
+			//kept for backward compat, internally we no longer use this action.
533
+			//@deprecated 4.8.36.rc.002
534
+			$contacts = $id_type === 'registration'
535
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
536
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
537
+			do_action(
538
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
539
+				$contacts,
540
+				$Message_Template_Group->ID()
541
+			);
542
+		}
543
+		$query_args = array(
544
+			'action' => ! empty($this->_req_data['redirect_back_to'])
545
+				? $this->_req_data['redirect_back_to']
546
+				: 'default',
547
+		);
548
+		$this->_redirect_after_action(false, '', '', $query_args, true);
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
555
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
556
+	 */
557
+	protected function _registration_reports_js_setup()
558
+	{
559
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
560
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 *        generates Business Reports regarding Registrations
567
+	 *
568
+	 * @access protected
569
+	 * @return void
570
+	 */
571
+	protected function _registration_reports()
572
+	{
573
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
574
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
575
+			$template_path,
576
+			$this->_reports_template_data,
577
+			true
578
+		);
579
+		// the final template wrapper
580
+		$this->display_admin_page_with_no_sidebar();
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Generates Business Report showing total registrations per day.
587
+	 *
588
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
589
+	 * @return string
590
+	 */
591
+	private function _registrations_per_day_report($period = '-1 month')
592
+	{
593
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
594
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
+		$results = (array)$results;
596
+		$regs = array();
597
+		$subtitle = '';
598
+		if ($results) {
599
+			$column_titles = array();
600
+			$tracker = 0;
601
+			foreach ($results as $result) {
602
+				$report_column_values = array();
603
+				foreach ($result as $property_name => $property_value) {
604
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
605
+						: (int)$property_value;
606
+					$report_column_values[] = $property_value;
607
+					if ($tracker === 0) {
608
+						if ($property_name === 'Registration_REG_date') {
609
+							$column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
610
+						} else {
611
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
612
+						}
613
+					}
614
+				}
615
+				$tracker++;
616
+				$regs[] = $report_column_values;
617
+			}
618
+			//make sure the column_titles is pushed to the beginning of the array
619
+			array_unshift($regs, $column_titles);
620
+			//setup the date range.
621
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
623
+			$ending_date = new DateTime("now", $DateTimeZone);
624
+			$subtitle = sprintf(
625
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
626
+				$beginning_date->format('Y-m-d'),
627
+				$ending_date->format('Y-m-d')
628
+			);
629
+		}
630
+		$report_title = __('Total Registrations per Day', 'event_espresso');
631
+		$report_params = array(
632
+			'title'     => $report_title,
633
+			'subtitle'  => $subtitle,
634
+			'id'        => $report_ID,
635
+			'regs'      => $regs,
636
+			'noResults' => empty($regs),
637
+			'noRegsMsg' => sprintf(
638
+				__(
639
+					'%sThere are currently no registration records in the last month for this report.%s',
640
+					'event_espresso'
641
+				),
642
+				'<h2>' . $report_title . '</h2><p>',
643
+				'</p>'
644
+			),
645
+		);
646
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
647
+		return $report_ID;
648
+	}
649
+
650
+
651
+
652
+	/**
653
+	 * Generates Business Report showing total registrations per event.
654
+	 *
655
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
656
+	 * @return string
657
+	 */
658
+	private function _registrations_per_event_report($period = '-1 month')
659
+	{
660
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
661
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
+		$results = (array)$results;
663
+		$regs = array();
664
+		$subtitle = '';
665
+		if ($results) {
666
+			$column_titles = array();
667
+			$tracker = 0;
668
+			foreach ($results as $result) {
669
+				$report_column_values = array();
670
+				foreach ($result as $property_name => $property_value) {
671
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
672
+						$property_value,
673
+						4,
674
+						'...'
675
+					) : (int)$property_value;
676
+					$report_column_values[] = $property_value;
677
+					if ($tracker === 0) {
678
+						if ($property_name === 'Registration_Event') {
679
+							$column_titles[] = __('Event', 'event_espresso');
680
+						} else {
681
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
682
+						}
683
+					}
684
+				}
685
+				$tracker++;
686
+				$regs[] = $report_column_values;
687
+			}
688
+			//make sure the column_titles is pushed to the beginning of the array
689
+			array_unshift($regs, $column_titles);
690
+			//setup the date range.
691
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
693
+			$ending_date = new DateTime("now", $DateTimeZone);
694
+			$subtitle = sprintf(
695
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
696
+				$beginning_date->format('Y-m-d'),
697
+				$ending_date->format('Y-m-d')
698
+			);
699
+		}
700
+		$report_title = __('Total Registrations per Event', 'event_espresso');
701
+		$report_params = array(
702
+			'title'     => $report_title,
703
+			'subtitle'  => $subtitle,
704
+			'id'        => $report_ID,
705
+			'regs'      => $regs,
706
+			'noResults' => empty($regs),
707
+			'noRegsMsg' => sprintf(
708
+				__(
709
+					'%sThere are currently no registration records in the last month for this report.%s',
710
+					'event_espresso'
711
+				),
712
+				'<h2>' . $report_title . '</h2><p>',
713
+				'</p>'
714
+			),
715
+		);
716
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
717
+		return $report_ID;
718
+	}
719
+
720
+
721
+
722
+	/**
723
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
724
+	 *
725
+	 * @access protected
726
+	 * @return void
727
+	 * @throws \EE_Error
728
+	 */
729
+	protected function _registration_checkin_list_table()
730
+	{
731
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
732
+		$reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
733
+		/** @var EE_Registration $registration */
734
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
735
+		$attendee = $registration->attendee();
736
+		$this->_admin_page_title .= $this->get_action_link_or_button(
737
+			'new_registration',
738
+			'add-registrant',
739
+			array('event_id' => $registration->event_ID()),
740
+			'add-new-h2'
741
+		);
742
+		$legend_items = array(
743
+			'checkin'  => array(
744
+				'class' => 'ee-icon ee-icon-check-in',
745
+				'desc'  => __('This indicates the attendee has been checked in', 'event_espresso'),
746
+			),
747
+			'checkout' => array(
748
+				'class' => 'ee-icon ee-icon-check-out',
749
+				'desc'  => __('This indicates the attendee has been checked out', 'event_espresso'),
750
+			),
751
+		);
752
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
753
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
754
+		/** @var EE_Datetime $datetime */
755
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
756
+		$datetime_label = '';
757
+		if ($datetime instanceof EE_Datetime) {
758
+			$datetime_label = $datetime->get_dtt_display_name(true);
759
+			$datetime_label .= ! empty($datetime_label)
760
+				? ' (' . $datetime->get_dtt_display_name() . ')'
761
+				: $datetime->get_dtt_display_name();
762
+		}
763
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
764
+			? EE_Admin_Page::add_query_args_and_nonce(
765
+				array(
766
+					'action'   => 'event_registrations',
767
+					'event_id' => $registration->event_ID(),
768
+					'DTT_ID'   => $dtt_id,
769
+				),
770
+				$this->_admin_base_url
771
+			)
772
+			: '';
773
+		$datetime_link = ! empty($datetime_link)
774
+			? '<a href="' . $datetime_link . '">'
775
+			  . '<span id="checkin-dtt">'
776
+			  . $datetime_label
777
+			  . '</span></a>'
778
+			: $datetime_label;
779
+		$attendee_name = $attendee instanceof EE_Attendee
780
+			? $attendee->full_name()
781
+			: '';
782
+		$attendee_link = $attendee instanceof EE_Attendee
783
+			? $attendee->get_admin_details_link()
784
+			: '';
785
+		$attendee_link = ! empty($attendee_link)
786
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
787
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
788
+			  . '<span id="checkin-attendee-name">'
789
+			  . $attendee_name
790
+			  . '</span></a>'
791
+			: '';
792
+		$event_link = $registration->event() instanceof EE_Event
793
+			? $registration->event()->get_admin_details_link()
794
+			: '';
795
+		$event_link = ! empty($event_link)
796
+			? '<a href="' . $event_link . '"'
797
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
798
+			  . '<span id="checkin-event-name">'
799
+			  . $registration->event_name()
800
+			  . '</span>'
801
+			  . '</a>'
802
+			: '';
803
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
+			? '<h2>' . sprintf(
805
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806
+				$attendee_link,
807
+				$datetime_link,
808
+				$event_link
809
+			) . '</h2>'
810
+			: '';
811
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
+			? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
813
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
815
+		$this->display_admin_list_table_page_with_no_sidebar();
816
+	}
817
+
818
+
819
+
820
+	/**
821
+	 * toggle the Check-in status for the given registration (coming from ajax)
822
+	 *
823
+	 * @return void (JSON)
824
+	 */
825
+	public function toggle_checkin_status()
826
+	{
827
+		//first make sure we have the necessary data
828
+		if ( ! isset($this->_req_data['_regid'])) {
829
+			EE_Error::add_error(
830
+				__(
831
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
832
+					'event_espresso'
833
+				),
834
+				__FILE__,
835
+				__FUNCTION__,
836
+				__LINE__
837
+			);
838
+			$this->_template_args['success'] = false;
839
+			$this->_template_args['error'] = true;
840
+			$this->_return_json();
841
+		};
842
+		//do a nonce check cause we're not coming in from an normal route here.
843
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
844
+			: '';
845
+		$nonce_ref = 'checkin_nonce';
846
+		$this->_verify_nonce($nonce, $nonce_ref);
847
+		//beautiful! Made it this far so let's get the status.
848
+		$new_status = $this->_toggle_checkin_status();
849
+		//setup new class to return via ajax
850
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'
851
+													  . $new_status;
852
+		$this->_template_args['success'] = true;
853
+		$this->_return_json();
854
+	}
855
+
856
+
857
+
858
+	/**
859
+	 * handles toggling the checkin status for the registration,
860
+	 *
861
+	 * @access protected
862
+	 * @return int|void
863
+	 */
864
+	protected function _toggle_checkin_status()
865
+	{
866
+		//first let's get the query args out of the way for the redirect
867
+		$query_args = array(
868
+			'action'   => 'event_registrations',
869
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
870
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
871
+		);
872
+		$new_status = false;
873
+		// bulk action check in toggle
874
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
+			// cycle thru checkboxes
876
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
877
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
878
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
879
+			}
880
+		} elseif (isset($this->_req_data['_regid'])) {
881
+			//coming from ajax request
882
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
883
+			$query_args['DTT_ID'] = $DTT_ID;
884
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
885
+		} else {
886
+			EE_Error::add_error(
887
+				__('Missing some required data to toggle the Check-in', 'event_espresso'),
888
+				__FILE__,
889
+				__FUNCTION__,
890
+				__LINE__
891
+			);
892
+		}
893
+		if (defined('DOING_AJAX')) {
894
+			return $new_status;
895
+		}
896
+		$this->_redirect_after_action(false, '', '', $query_args, true);
897
+	}
898
+
899
+
900
+
901
+	/**
902
+	 * This is toggles a single Check-in for the given registration and datetime.
903
+	 *
904
+	 * @param  int $REG_ID The registration we're toggling
905
+	 * @param  int $DTT_ID The datetime we're toggling
906
+	 * @return int            The new status toggled to.
907
+	 * @throws \EE_Error
908
+	 */
909
+	private function _toggle_checkin($REG_ID, $DTT_ID)
910
+	{
911
+		/** @var EE_Registration $REG */
912
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
913
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
914
+		if ($new_status !== false) {
915
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
916
+		} else {
917
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
918
+			$new_status = false;
919
+		}
920
+		return $new_status;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * Takes care of deleting multiple EE_Checkin table rows
927
+	 *
928
+	 * @access protected
929
+	 * @return void
930
+	 * @throws \EE_Error
931
+	 */
932
+	protected function _delete_checkin_rows()
933
+	{
934
+		$query_args = array(
935
+			'action' => 'registration_checkins',
936
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
937
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
938
+		);
939
+		$errors = 0;
940
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
941
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
942
+				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
943
+					$errors++;
944
+				}
945
+			}
946
+		} else {
947
+			EE_Error::add_error(
948
+				__(
949
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
950
+					'event_espresso'
951
+				),
952
+				__FILE__,
953
+				__FUNCTION__,
954
+				__LINE__
955
+			);
956
+			$this->_redirect_after_action(false, '', '', $query_args, true);
957
+		}
958
+		if ($errors > 0) {
959
+			EE_Error::add_error(
960
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
961
+				__FILE__,
962
+				__FUNCTION__,
963
+				__LINE__
964
+			);
965
+		} else {
966
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
967
+		}
968
+		$this->_redirect_after_action(false, '', '', $query_args, true);
969
+	}
970
+
971
+
972
+
973
+	/**
974
+	 * Deletes a single EE_Checkin row
975
+	 *
976
+	 * @return void
977
+	 * @throws \EE_Error
978
+	 */
979
+	protected function _delete_checkin_row()
980
+	{
981
+		$query_args = array(
982
+			'action' => 'registration_checkins',
983
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
984
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
985
+		);
986
+		if ( ! empty($this->_req_data['CHK_ID'])) {
987
+			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
988
+				EE_Error::add_error(
989
+					__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
990
+					__FILE__,
991
+					__FUNCTION__,
992
+					__LINE__
993
+				);
994
+			} else {
995
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
996
+			}
997
+		} else {
998
+			EE_Error::add_error(
999
+				__(
1000
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1001
+					'event_espresso'
1002
+				),
1003
+				__FILE__,
1004
+				__FUNCTION__,
1005
+				__LINE__
1006
+			);
1007
+		}
1008
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 *        generates HTML for the Event Registrations List Table
1015
+	 *
1016
+	 * @access protected
1017
+	 * @return void
1018
+	 * @throws \EE_Error
1019
+	 */
1020
+	protected function _event_registrations_list_table()
1021
+	{
1022
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1023
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1024
+			? $this->get_action_link_or_button(
1025
+				'new_registration',
1026
+				'add-registrant',
1027
+				array('event_id' => $this->_req_data['event_id']),
1028
+				'add-new-h2',
1029
+				'',
1030
+				false
1031
+			)
1032
+			: '';
1033
+		$legend_items = array(
1034
+			'star-icon'        => array(
1035
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
+				'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1037
+			),
1038
+			'checkin'          => array(
1039
+				'class' => 'ee-icon ee-icon-check-in',
1040
+				'desc'  => __('This Registrant has been Checked In', 'event_espresso'),
1041
+			),
1042
+			'checkout'         => array(
1043
+				'class' => 'ee-icon ee-icon-check-out',
1044
+				'desc'  => __('This Registrant has been Checked Out', 'event_espresso'),
1045
+			),
1046
+			'nocheckinrecord'  => array(
1047
+				'class' => 'dashicons dashicons-no',
1048
+				'desc'  => __('No Check-in Record has been Created for this Registrant', 'event_espresso'),
1049
+			),
1050
+			'view_details'     => array(
1051
+				'class' => 'dashicons dashicons-search',
1052
+				'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053
+			),
1054
+			'approved_status'  => array(
1055
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1056
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057
+			),
1058
+			'cancelled_status' => array(
1059
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1060
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061
+			),
1062
+			'declined_status'  => array(
1063
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1064
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065
+			),
1066
+			'not_approved'     => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069
+			),
1070
+			'pending_status'   => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073
+			),
1074
+			'wait_list'        => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077
+			),
1078
+		);
1079
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081
+		$this->_template_args['before_list_table'] = ! empty($event_id)
1082
+			? '<h2>' . sprintf(
1083
+				__('Viewing Registrations for Event: %s', 'event_espresso'),
1084
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
+			) . '</h2>'
1086
+			: '';
1087
+		//need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088
+		/** @var EE_Event $event */
1089
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1090
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1091
+		$datetime = null;
1092
+		if ($event instanceof EE_Event) {
1093
+			$datetimes_on_event = $event->datetimes();
1094
+			if (count($datetimes_on_event) === 1) {
1095
+				$datetime = reset($datetimes_on_event);
1096
+			}
1097
+		}
1098
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1099
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1100
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1101
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103
+			$this->_template_args['before_list_table'] .= $datetime->name();
1104
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1105
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1106
+		}
1107
+		//if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1108
+		//represents
1109
+		if ( ! $datetime instanceof EE_Datetime) {
1110
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1111
+														  . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1112
+					'event_espresso')
1113
+														  . '</p>';
1114
+		}
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+	/**
1119
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1120
+	 * conditions)
1121
+	 *
1122
+	 * @return void ends the request by a redirect or download
1123
+	 */
1124
+	public function _registrations_checkin_report()
1125
+	{
1126
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1127
+	}
1128
+
1129
+	/**
1130
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1131
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1132
+	 *
1133
+	 * @param array     $request
1134
+	 * @param int  $per_page
1135
+	 * @param bool $count
1136
+	 * @return array
1137
+	 */
1138
+	protected function _get_checkin_query_params_from_request(
1139
+		$request,
1140
+		$per_page = 10,
1141
+		$count = false
1142
+	) {
1143
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1144
+		//unlike the regular registrations list table,
1145
+		$status_ids_array = apply_filters(
1146
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1147
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1148
+		);
1149
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1150
+		return $query_params;
1151
+	}
1152
+
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * Gets registrations for an event
1158
+	 *
1159
+	 * @param int    $per_page
1160
+	 * @param bool   $count whether to return count or data.
1161
+	 * @param bool   $trash
1162
+	 * @param string $orderby
1163
+	 * @return EE_Registration[]|int
1164
+	 * @throws \EE_Error
1165
+	 */
1166
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1167
+	{
1168
+		//normalize some request params that get setup by the parent `get_registrations` method.
1169
+		$request = $this->_req_data;
1170
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
+		$request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
+		if($trash){
1173
+			$request['status'] = 'trash';
1174
+		}
1175
+		$query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1176
+		/**
1177
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1179
+		 * @see EEM_Base::get_all()
1180
+		 */
1181
+		$query_params['group_by'] = '';
1182
+
1183
+		return $count
1184
+			? EEM_Registration::instance()->count($query_params)
1185
+			/** @type EE_Registration[] */
1186
+			: EEM_Registration::instance()->get_all($query_params);
1187
+	}
1188 1188
 
1189 1189
 } //end class Registrations Admin Page
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
     {
36 36
         parent::__construct($routing);
37 37
         if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
38
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
39
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
40
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
41 41
         }
42 42
     }
43 43
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
             //enqueue newsletter js
179 179
             wp_enqueue_script(
180 180
                 'ee-newsletter-trigger',
181
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
181
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
182 182
                 array('ee-dialog'),
183 183
                 EVENT_ESPRESSO_VERSION,
184 184
                 true
185 185
             );
186 186
             wp_enqueue_style(
187 187
                 'ee-newsletter-trigger-css',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
188
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
189 189
                 array(),
190 190
                 EVENT_ESPRESSO_VERSION
191 191
             );
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     {
205 205
         wp_register_script(
206 206
             'ee-reg-reports-js',
207
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
207
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
208 208
             array('google-charts'),
209 209
             EVENT_ESPRESSO_VERSION,
210 210
             true
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             $codes[$field] = implode(', ', array_keys($shortcode_array));
410 410
         }
411 411
         $shortcodes = $codes;
412
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
412
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
413 413
         $form_template_args = array(
414 414
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415 415
             'form_route'        => 'newsletter_selected_send',
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
      */
571 571
     protected function _registration_reports()
572 572
     {
573
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
573
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
574 574
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
575 575
             $template_path,
576 576
             $this->_reports_template_data,
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
     {
593 593
         $report_ID = 'reg-admin-registrations-per-day-report-dv';
594 594
         $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
-        $results = (array)$results;
595
+        $results = (array) $results;
596 596
         $regs = array();
597 597
         $subtitle = '';
598 598
         if ($results) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                 $report_column_values = array();
603 603
                 foreach ($result as $property_name => $property_value) {
604 604
                     $property_value = $property_name === 'Registration_REG_date' ? $property_value
605
-                        : (int)$property_value;
605
+                        : (int) $property_value;
606 606
                     $report_column_values[] = $property_value;
607 607
                     if ($tracker === 0) {
608 608
                         if ($property_name === 'Registration_REG_date') {
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
             array_unshift($regs, $column_titles);
620 620
             //setup the date range.
621 621
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
622
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
623 623
             $ending_date = new DateTime("now", $DateTimeZone);
624 624
             $subtitle = sprintf(
625 625
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                     '%sThere are currently no registration records in the last month for this report.%s',
640 640
                     'event_espresso'
641 641
                 ),
642
-                '<h2>' . $report_title . '</h2><p>',
642
+                '<h2>'.$report_title.'</h2><p>',
643 643
                 '</p>'
644 644
             ),
645 645
         );
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
     {
660 660
         $report_ID = 'reg-admin-registrations-per-event-report-dv';
661 661
         $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
-        $results = (array)$results;
662
+        $results = (array) $results;
663 663
         $regs = array();
664 664
         $subtitle = '';
665 665
         if ($results) {
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
                         $property_value,
673 673
                         4,
674 674
                         '...'
675
-                    ) : (int)$property_value;
675
+                    ) : (int) $property_value;
676 676
                     $report_column_values[] = $property_value;
677 677
                     if ($tracker === 0) {
678 678
                         if ($property_name === 'Registration_Event') {
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
             array_unshift($regs, $column_titles);
690 690
             //setup the date range.
691 691
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
692
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
693 693
             $ending_date = new DateTime("now", $DateTimeZone);
694 694
             $subtitle = sprintf(
695 695
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
                     '%sThere are currently no registration records in the last month for this report.%s',
710 710
                     'event_espresso'
711 711
                 ),
712
-                '<h2>' . $report_title . '</h2><p>',
712
+                '<h2>'.$report_title.'</h2><p>',
713 713
                 '</p>'
714 714
             ),
715 715
         );
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         if ($datetime instanceof EE_Datetime) {
758 758
             $datetime_label = $datetime->get_dtt_display_name(true);
759 759
             $datetime_label .= ! empty($datetime_label)
760
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
760
+                ? ' ('.$datetime->get_dtt_display_name().')'
761 761
                 : $datetime->get_dtt_display_name();
762 762
         }
763 763
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
             )
772 772
             : '';
773 773
         $datetime_link = ! empty($datetime_link)
774
-            ? '<a href="' . $datetime_link . '">'
774
+            ? '<a href="'.$datetime_link.'">'
775 775
               . '<span id="checkin-dtt">'
776 776
               . $datetime_label
777 777
               . '</span></a>'
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
             ? $attendee->get_admin_details_link()
784 784
             : '';
785 785
         $attendee_link = ! empty($attendee_link)
786
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
787
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
786
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
787
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
788 788
               . '<span id="checkin-attendee-name">'
789 789
               . $attendee_name
790 790
               . '</span></a>'
@@ -793,25 +793,25 @@  discard block
 block discarded – undo
793 793
             ? $registration->event()->get_admin_details_link()
794 794
             : '';
795 795
         $event_link = ! empty($event_link)
796
-            ? '<a href="' . $event_link . '"'
797
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
796
+            ? '<a href="'.$event_link.'"'
797
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
798 798
               . '<span id="checkin-event-name">'
799 799
               . $registration->event_name()
800 800
               . '</span>'
801 801
               . '</a>'
802 802
             : '';
803 803
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
-            ? '<h2>' . sprintf(
804
+            ? '<h2>'.sprintf(
805 805
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806 806
                 $attendee_link,
807 807
                 $datetime_link,
808 808
                 $event_link
809
-            ) . '</h2>'
809
+            ).'</h2>'
810 810
             : '';
811 811
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
812
+            ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : '';
813 813
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
814
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
815 815
         $this->display_admin_list_table_page_with_no_sidebar();
816 816
     }
817 817
 
@@ -1052,37 +1052,37 @@  discard block
 block discarded – undo
1052 1052
                 'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053 1053
             ),
1054 1054
             'approved_status'  => array(
1055
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1055
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1056 1056
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057 1057
             ),
1058 1058
             'cancelled_status' => array(
1059
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1059
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1060 1060
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061 1061
             ),
1062 1062
             'declined_status'  => array(
1063
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1063
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1064 1064
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065 1065
             ),
1066 1066
             'not_approved'     => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1067
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1068 1068
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069 1069
             ),
1070 1070
             'pending_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1071
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1072 1072
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073 1073
             ),
1074 1074
             'wait_list'        => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1075
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1076 1076
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077 1077
             ),
1078 1078
         );
1079 1079
         $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080 1080
         $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081 1081
         $this->_template_args['before_list_table'] = ! empty($event_id)
1082
-            ? '<h2>' . sprintf(
1082
+            ? '<h2>'.sprintf(
1083 1083
                 __('Viewing Registrations for Event: %s', 'event_espresso'),
1084 1084
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
-            ) . '</h2>'
1085
+            ).'</h2>'
1086 1086
             : '';
1087 1087
         //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088 1088
         /** @var EE_Event $event */
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102 1102
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103 1103
             $this->_template_args['before_list_table'] .= $datetime->name();
1104
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1104
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1105 1105
             $this->_template_args['before_list_table'] .= '</span></h2>';
1106 1106
         }
1107 1107
         //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
@@ -1168,11 +1168,11 @@  discard block
 block discarded – undo
1168 1168
         //normalize some request params that get setup by the parent `get_registrations` method.
1169 1169
         $request = $this->_req_data;
1170 1170
         $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
-        if($trash){
1171
+        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
+        if ($trash) {
1173 1173
             $request['status'] = 'trash';
1174 1174
         }
1175
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1175
+        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1176 1176
         /**
1177 1177
          * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178 1178
          * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -22,103 +22,103 @@
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * @var LoaderDecoratorInterface $new_loader
27
-     */
28
-    private $new_loader;
29
-
30
-
31
-    /**
32
-     * @var LoaderDecoratorInterface $shared_loader
33
-     */
34
-    private $shared_loader;
35
-
36
-
37
-
38
-    /**
39
-     * Loader constructor.
40
-     *
41
-     * @param LoaderDecoratorInterface|null $new_loader
42
-     * @param LoaderDecoratorInterface|null $shared_loader
43
-     * @throws InvalidInterfaceException
44
-     * @throws InvalidArgumentException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader)
48
-    {
49
-        $this->new_loader = $new_loader;
50
-        $this->shared_loader = $shared_loader;
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * @return LoaderDecoratorInterface
57
-     */
58
-    public function getNewLoader()
59
-    {
60
-        return $this->new_loader;
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * @return LoaderDecoratorInterface
67
-     */
68
-    public function getSharedLoader()
69
-    {
70
-        return $this->shared_loader;
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     * @param string $fqcn
77
-     * @param array  $arguments
78
-     * @param bool   $shared
79
-     * @return mixed
80
-     */
81
-    public function load($fqcn, $arguments = array(), $shared = true)
82
-    {
83
-        return $shared
84
-            ? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
85
-            : $this->getNewLoader()->load($fqcn, $arguments, $shared);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @param string $fqcn
92
-     * @param array  $arguments
93
-     * @return mixed
94
-     */
95
-    public function getNew($fqcn, $arguments = array())
96
-    {
97
-        return $this->getNewLoader()->load($fqcn, $arguments, false);
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * @param string $fqcn
104
-     * @param array  $arguments
105
-     * @return mixed
106
-     */
107
-    public function getShared($fqcn, $arguments = array())
108
-    {
109
-        return $this->getSharedLoader()->load($fqcn, $arguments, true);
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * calls reset() on loaders if that method exists
116
-     */
117
-    public function reset()
118
-    {
119
-        $this->new_loader->reset();
120
-        $this->shared_loader->reset();
121
-    }
25
+	/**
26
+	 * @var LoaderDecoratorInterface $new_loader
27
+	 */
28
+	private $new_loader;
29
+
30
+
31
+	/**
32
+	 * @var LoaderDecoratorInterface $shared_loader
33
+	 */
34
+	private $shared_loader;
35
+
36
+
37
+
38
+	/**
39
+	 * Loader constructor.
40
+	 *
41
+	 * @param LoaderDecoratorInterface|null $new_loader
42
+	 * @param LoaderDecoratorInterface|null $shared_loader
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws InvalidArgumentException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader)
48
+	{
49
+		$this->new_loader = $new_loader;
50
+		$this->shared_loader = $shared_loader;
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * @return LoaderDecoratorInterface
57
+	 */
58
+	public function getNewLoader()
59
+	{
60
+		return $this->new_loader;
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * @return LoaderDecoratorInterface
67
+	 */
68
+	public function getSharedLoader()
69
+	{
70
+		return $this->shared_loader;
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 * @param string $fqcn
77
+	 * @param array  $arguments
78
+	 * @param bool   $shared
79
+	 * @return mixed
80
+	 */
81
+	public function load($fqcn, $arguments = array(), $shared = true)
82
+	{
83
+		return $shared
84
+			? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
85
+			: $this->getNewLoader()->load($fqcn, $arguments, $shared);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @param string $fqcn
92
+	 * @param array  $arguments
93
+	 * @return mixed
94
+	 */
95
+	public function getNew($fqcn, $arguments = array())
96
+	{
97
+		return $this->getNewLoader()->load($fqcn, $arguments, false);
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * @param string $fqcn
104
+	 * @param array  $arguments
105
+	 * @return mixed
106
+	 */
107
+	public function getShared($fqcn, $arguments = array())
108
+	{
109
+		return $this->getSharedLoader()->load($fqcn, $arguments, true);
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * calls reset() on loaders if that method exists
116
+	 */
117
+	public function reset()
118
+	{
119
+		$this->new_loader->reset();
120
+		$this->shared_loader->reset();
121
+	}
122 122
 
123 123
 }
124 124
 // End of file Loader.php
Please login to merge, or discard this patch.
core/services/loaders/CoreLoader.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -26,67 +26,67 @@
 block discarded – undo
26 26
 class CoreLoader implements LoaderDecoratorInterface
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Registry|CoffeeShop $generator
31
-     */
32
-    private $generator;
33
-
34
-
35
-
36
-    /**
37
-     * CoreLoader constructor.
38
-     *
39
-     * @param EE_Registry|CoffeeShop $generator
40
-     * @throws InvalidArgumentException
41
-     */
42
-    public function __construct($generator)
43
-    {
44
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
45
-            throw new InvalidArgumentException(
46
-                esc_html__(
47
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
48
-                    'event_espresso'
49
-                )
50
-            );
51
-        }
52
-        $this->generator = $generator;
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * @param string $fqcn
59
-     * @param array  $arguments
60
-     * @param bool   $shared
61
-     * @return mixed
62
-     * @throws EE_Error
63
-     * @throws ServiceNotFoundException
64
-     * @throws ReflectionException
65
-     */
66
-    public function load($fqcn, $arguments = array(), $shared = true)
67
-    {
68
-        if($this->generator instanceof EE_Registry) {
69
-            return $this->generator->create($fqcn, $arguments, $shared);
70
-        }
71
-        $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW;
72
-        return $this->generator->brew($fqcn, $arguments, $shared);
73
-
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * calls reset() on generator if method exists
80
-     *
81
-     * @throws EE_Error
82
-     * @throws ReflectionException
83
-     */
84
-    public function reset()
85
-    {
86
-        if (method_exists($this->generator, 'reset')) {
87
-            $this->generator->reset();
88
-        }
89
-    }
29
+	/**
30
+	 * @var EE_Registry|CoffeeShop $generator
31
+	 */
32
+	private $generator;
33
+
34
+
35
+
36
+	/**
37
+	 * CoreLoader constructor.
38
+	 *
39
+	 * @param EE_Registry|CoffeeShop $generator
40
+	 * @throws InvalidArgumentException
41
+	 */
42
+	public function __construct($generator)
43
+	{
44
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
45
+			throw new InvalidArgumentException(
46
+				esc_html__(
47
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
48
+					'event_espresso'
49
+				)
50
+			);
51
+		}
52
+		$this->generator = $generator;
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * @param string $fqcn
59
+	 * @param array  $arguments
60
+	 * @param bool   $shared
61
+	 * @return mixed
62
+	 * @throws EE_Error
63
+	 * @throws ServiceNotFoundException
64
+	 * @throws ReflectionException
65
+	 */
66
+	public function load($fqcn, $arguments = array(), $shared = true)
67
+	{
68
+		if($this->generator instanceof EE_Registry) {
69
+			return $this->generator->create($fqcn, $arguments, $shared);
70
+		}
71
+		$shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW;
72
+		return $this->generator->brew($fqcn, $arguments, $shared);
73
+
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * calls reset() on generator if method exists
80
+	 *
81
+	 * @throws EE_Error
82
+	 * @throws ReflectionException
83
+	 */
84
+	public function reset()
85
+	{
86
+		if (method_exists($this->generator, 'reset')) {
87
+			$this->generator->reset();
88
+		}
89
+	}
90 90
 
91 91
 }
92 92
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Shortcode.lib.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -20,159 +20,159 @@
 block discarded – undo
20 20
 class EE_Register_Shortcode implements EEI_Plugin_API
21 21
 {
22 22
 
23
-    /**
24
-     * Holds values for registered shortcodes
25
-     *
26
-     * @var array
27
-     */
28
-    protected static $_settings = array();
23
+	/**
24
+	 * Holds values for registered shortcodes
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected static $_settings = array();
29 29
 
30 30
 
31
-    /**
32
-     *    Method for registering new EE_Shortcodes
33
-     *
34
-     * @since    4.3.0
35
-     * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
36
-     * @param string $shortcode_id a unique identifier for this set of modules Required.
37
-     * @param  array $setup_args   an array of arguments provided for registering shortcodes Required.
38
-     *               @type array shortcode_paths        an array of full server paths to folders containing any
39
-     *                                                  EES_Shortcodes
40
-     *               @type array shortcode_fqcns        an array of fully qualified class names for any new shortcode
41
-     *                                                  classes to register.  Shortcode classes should extend
42
-     *                                                  EspressoShortcode and be properly namespaced so they are
43
-     *                                                  autoloaded.
44
-     * @throws EE_Error
45
-     * @return void
46
-     */
47
-    public static function register($shortcode_id = null, $setup_args = array())
48
-    {
49
-        //required fields MUST be present, so let's make sure they are.
50
-        if (empty($shortcode_id)
51
-            || ! is_array($setup_args)
52
-            || (
53
-                empty($setup_args['shortcode_paths']))
54
-                && empty($setup_args['shortcode_fqcns'])
55
-            ) {
56
-            throw new EE_Error(
57
-                esc_html__(
58
-                    'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
59
-                    'event_espresso'
60
-                )
61
-            );
62
-        }
31
+	/**
32
+	 *    Method for registering new EE_Shortcodes
33
+	 *
34
+	 * @since    4.3.0
35
+	 * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
36
+	 * @param string $shortcode_id a unique identifier for this set of modules Required.
37
+	 * @param  array $setup_args   an array of arguments provided for registering shortcodes Required.
38
+	 *               @type array shortcode_paths        an array of full server paths to folders containing any
39
+	 *                                                  EES_Shortcodes
40
+	 *               @type array shortcode_fqcns        an array of fully qualified class names for any new shortcode
41
+	 *                                                  classes to register.  Shortcode classes should extend
42
+	 *                                                  EspressoShortcode and be properly namespaced so they are
43
+	 *                                                  autoloaded.
44
+	 * @throws EE_Error
45
+	 * @return void
46
+	 */
47
+	public static function register($shortcode_id = null, $setup_args = array())
48
+	{
49
+		//required fields MUST be present, so let's make sure they are.
50
+		if (empty($shortcode_id)
51
+			|| ! is_array($setup_args)
52
+			|| (
53
+				empty($setup_args['shortcode_paths']))
54
+				&& empty($setup_args['shortcode_fqcns'])
55
+			) {
56
+			throw new EE_Error(
57
+				esc_html__(
58
+					'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
59
+					'event_espresso'
60
+				)
61
+			);
62
+		}
63 63
 
64
-        //make sure we don't register twice
65
-        if (isset(self::$_settings[$shortcode_id])) {
66
-            return;
67
-        }
64
+		//make sure we don't register twice
65
+		if (isset(self::$_settings[$shortcode_id])) {
66
+			return;
67
+		}
68 68
 
69
-        //make sure this was called in the right place!
70
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
71
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72
-        ) {
73
-            EE_Error::doing_it_wrong(
74
-                __METHOD__,
75
-                esc_html__(
76
-                    'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
77
-                    'event_espresso'
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        //setup $_settings array from incoming values.
83
-        self::$_settings[$shortcode_id] = array(
84
-            // array of full server paths to any EES_Shortcodes used by the shortcode
85
-            'shortcode_paths' => isset($setup_args['shortcode_paths'])
86
-                ? (array) $setup_args['shortcode_paths']
87
-                : array(),
88
-            'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
89
-                ? (array) $setup_args['shortcode_fqcns']
90
-                : array()
91
-        );
92
-        // add to list of shortcodes to be registered
93
-        add_filter(
94
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
95
-            array('EE_Register_Shortcode', 'add_shortcodes')
96
-        );
69
+		//make sure this was called in the right place!
70
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
71
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72
+		) {
73
+			EE_Error::doing_it_wrong(
74
+				__METHOD__,
75
+				esc_html__(
76
+					'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
77
+					'event_espresso'
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		//setup $_settings array from incoming values.
83
+		self::$_settings[$shortcode_id] = array(
84
+			// array of full server paths to any EES_Shortcodes used by the shortcode
85
+			'shortcode_paths' => isset($setup_args['shortcode_paths'])
86
+				? (array) $setup_args['shortcode_paths']
87
+				: array(),
88
+			'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
89
+				? (array) $setup_args['shortcode_fqcns']
90
+				: array()
91
+		);
92
+		// add to list of shortcodes to be registered
93
+		add_filter(
94
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
95
+			array('EE_Register_Shortcode', 'add_shortcodes')
96
+		);
97 97
 
98
-        add_filter(
99
-            'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
100
-            array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection')
101
-        );
102
-    }
98
+		add_filter(
99
+			'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
100
+			array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection')
101
+		);
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * Filters the list of shortcodes to add ours.
107
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
108
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...)
109
-     *
110
-     * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
111
-     * @return array
112
-     */
113
-    public static function add_shortcodes($shortcodes_to_register)
114
-    {
115
-        foreach (self::$_settings as $settings) {
116
-            $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
117
-        }
118
-        return $shortcodes_to_register;
119
-    }
105
+	/**
106
+	 * Filters the list of shortcodes to add ours.
107
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
108
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...)
109
+	 *
110
+	 * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
111
+	 * @return array
112
+	 */
113
+	public static function add_shortcodes($shortcodes_to_register)
114
+	{
115
+		foreach (self::$_settings as $settings) {
116
+			$shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
117
+		}
118
+		return $shortcodes_to_register;
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection
124
-     * and registers any provided shortcode fully qualified class names.
125
-     * @param CollectionInterface $shortcodes_collection
126
-     * @return CollectionInterface
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidClassException
129
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
130
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
131
-     */
132
-    public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
133
-    {
134
-        foreach (self::$_settings as $settings) {
135
-            if (! empty($settings['shortcode_fqcns'])) {
136
-                foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
137
-                    if (! class_exists($shortcode_fqcn)) {
138
-                        throw new InvalidClassException(
139
-                            sprintf(
140
-                                esc_html__(
141
-                                    'Are you sure %s is the right fully qualified class name for the shortcode class?',
142
-                                    'event_espresso'
143
-                                ),
144
-                                $shortcode_fqcn
145
-                            )
146
-                        );
147
-                    }
148
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
149
-                        //register dependencies
150
-                        EE_Dependency_Map::register_dependencies(
151
-                            $shortcode_fqcn,
152
-                            array(
153
-                                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
154
-                            )
155
-                        );
156
-                    }
157
-                    $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
158
-                }
159
-            }
160
-        }
161
-        return $shortcodes_collection;
162
-    }
122
+	/**
123
+	 * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection
124
+	 * and registers any provided shortcode fully qualified class names.
125
+	 * @param CollectionInterface $shortcodes_collection
126
+	 * @return CollectionInterface
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidClassException
129
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
130
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
131
+	 */
132
+	public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
133
+	{
134
+		foreach (self::$_settings as $settings) {
135
+			if (! empty($settings['shortcode_fqcns'])) {
136
+				foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
137
+					if (! class_exists($shortcode_fqcn)) {
138
+						throw new InvalidClassException(
139
+							sprintf(
140
+								esc_html__(
141
+									'Are you sure %s is the right fully qualified class name for the shortcode class?',
142
+									'event_espresso'
143
+								),
144
+								$shortcode_fqcn
145
+							)
146
+						);
147
+					}
148
+					if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
149
+						//register dependencies
150
+						EE_Dependency_Map::register_dependencies(
151
+							$shortcode_fqcn,
152
+							array(
153
+								'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
154
+							)
155
+						);
156
+					}
157
+					$shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
158
+				}
159
+			}
160
+		}
161
+		return $shortcodes_collection;
162
+	}
163 163
 
164 164
 
165
-    /**
166
-     * This deregisters a shortcode that was previously registered with a specific $shortcode_id.
167
-     *
168
-     * @since    4.3.0
169
-     * @param string $shortcode_id the name for the shortcode that was previously registered
170
-     * @return void
171
-     */
172
-    public static function deregister($shortcode_id = null)
173
-    {
174
-        if (isset(self::$_settings[$shortcode_id])) {
175
-            unset(self::$_settings[$shortcode_id]);
176
-        }
177
-    }
165
+	/**
166
+	 * This deregisters a shortcode that was previously registered with a specific $shortcode_id.
167
+	 *
168
+	 * @since    4.3.0
169
+	 * @param string $shortcode_id the name for the shortcode that was previously registered
170
+	 * @return void
171
+	 */
172
+	public static function deregister($shortcode_id = null)
173
+	{
174
+		if (isset(self::$_settings[$shortcode_id])) {
175
+			unset(self::$_settings[$shortcode_id]);
176
+		}
177
+	}
178 178
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         }
68 68
 
69 69
         //make sure this was called in the right place!
70
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
70
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
71 71
             || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72 72
         ) {
73 73
             EE_Error::doing_it_wrong(
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
     public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
133 133
     {
134 134
         foreach (self::$_settings as $settings) {
135
-            if (! empty($settings['shortcode_fqcns'])) {
135
+            if ( ! empty($settings['shortcode_fqcns'])) {
136 136
                 foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
137
-                    if (! class_exists($shortcode_fqcn)) {
137
+                    if ( ! class_exists($shortcode_fqcn)) {
138 138
                         throw new InvalidClassException(
139 139
                             sprintf(
140 140
                                 esc_html__(
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                             )
146 146
                         );
147 147
                     }
148
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
148
+                    if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
149 149
                         //register dependencies
150 150
                         EE_Dependency_Map::register_dependencies(
151 151
                             $shortcode_fqcn,
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1005 added lines, -1005 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -19,1064 +19,1064 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * possibly truncated version of the EE core version string
24
-     *
25
-     * @var string
26
-     */
27
-    protected static $_core_version = '';
22
+	/**
23
+	 * possibly truncated version of the EE core version string
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected static $_core_version = '';
28 28
 
29
-    /**
30
-     * Holds values for registered addons
31
-     *
32
-     * @var array
33
-     */
34
-    protected static $_settings = array();
29
+	/**
30
+	 * Holds values for registered addons
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected static $_settings = array();
35 35
 
36
-    /**
37
-     * @var  array $_incompatible_addons keys are addon SLUGS
38
-     * (first argument passed to EE_Register_Addon::register()), keys are
39
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
40
-     * Generally this should be used sparingly, as we don't want to muddle up
41
-     * EE core with knowledge of ALL the addons out there.
42
-     * If you want NO versions of an addon to run with a certain version of core,
43
-     * it's usually best to define the addon's "min_core_version" as part of its call
44
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
45
-     * minimum plugin version.
46
-     * @access    protected
47
-     */
48
-    protected static $_incompatible_addons = array(
49
-        'Multi_Event_Registration' => '2.0.11.rc.002',
50
-        'Promotions'               => '1.0.0.rc.084',
51
-    );
36
+	/**
37
+	 * @var  array $_incompatible_addons keys are addon SLUGS
38
+	 * (first argument passed to EE_Register_Addon::register()), keys are
39
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
40
+	 * Generally this should be used sparingly, as we don't want to muddle up
41
+	 * EE core with knowledge of ALL the addons out there.
42
+	 * If you want NO versions of an addon to run with a certain version of core,
43
+	 * it's usually best to define the addon's "min_core_version" as part of its call
44
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
45
+	 * minimum plugin version.
46
+	 * @access    protected
47
+	 */
48
+	protected static $_incompatible_addons = array(
49
+		'Multi_Event_Registration' => '2.0.11.rc.002',
50
+		'Promotions'               => '1.0.0.rc.084',
51
+	);
52 52
 
53 53
 
54
-    /**
55
-     * We should always be comparing core to a version like '4.3.0.rc.000',
56
-     * not just '4.3.0'.
57
-     * So if the addon developer doesn't provide that full version string,
58
-     * fill in the blanks for them
59
-     *
60
-     * @param string $min_core_version
61
-     * @return string always like '4.3.0.rc.000'
62
-     */
63
-    protected static function _effective_version($min_core_version)
64
-    {
65
-        // versions: 4 . 3 . 1 . p . 123
66
-        // offsets:    0 . 1 . 2 . 3 . 4
67
-        $version_parts = explode('.', $min_core_version);
68
-        //check they specified the micro version (after 2nd period)
69
-        if (! isset($version_parts[2])) {
70
-            $version_parts[2] = '0';
71
-        }
72
-        //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73
-        //soon we can assume that's 'rc', but this current version is 'alpha'
74
-        if (! isset($version_parts[3])) {
75
-            $version_parts[3] = 'dev';
76
-        }
77
-        if (! isset($version_parts[4])) {
78
-            $version_parts[4] = '000';
79
-        }
80
-        return implode('.', $version_parts);
81
-    }
54
+	/**
55
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
56
+	 * not just '4.3.0'.
57
+	 * So if the addon developer doesn't provide that full version string,
58
+	 * fill in the blanks for them
59
+	 *
60
+	 * @param string $min_core_version
61
+	 * @return string always like '4.3.0.rc.000'
62
+	 */
63
+	protected static function _effective_version($min_core_version)
64
+	{
65
+		// versions: 4 . 3 . 1 . p . 123
66
+		// offsets:    0 . 1 . 2 . 3 . 4
67
+		$version_parts = explode('.', $min_core_version);
68
+		//check they specified the micro version (after 2nd period)
69
+		if (! isset($version_parts[2])) {
70
+			$version_parts[2] = '0';
71
+		}
72
+		//if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73
+		//soon we can assume that's 'rc', but this current version is 'alpha'
74
+		if (! isset($version_parts[3])) {
75
+			$version_parts[3] = 'dev';
76
+		}
77
+		if (! isset($version_parts[4])) {
78
+			$version_parts[4] = '000';
79
+		}
80
+		return implode('.', $version_parts);
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * Returns whether or not the min core version requirement of the addon is met
86
-     *
87
-     * @param string $min_core_version    the minimum core version required by the addon
88
-     * @param string $actual_core_version the actual core version, optional
89
-     * @return boolean
90
-     */
91
-    public static function _meets_min_core_version_requirement(
92
-        $min_core_version,
93
-        $actual_core_version = EVENT_ESPRESSO_VERSION
94
-    ) {
95
-        return version_compare(
96
-            self::_effective_version($actual_core_version),
97
-            self::_effective_version($min_core_version),
98
-            '>='
99
-        );
100
-    }
84
+	/**
85
+	 * Returns whether or not the min core version requirement of the addon is met
86
+	 *
87
+	 * @param string $min_core_version    the minimum core version required by the addon
88
+	 * @param string $actual_core_version the actual core version, optional
89
+	 * @return boolean
90
+	 */
91
+	public static function _meets_min_core_version_requirement(
92
+		$min_core_version,
93
+		$actual_core_version = EVENT_ESPRESSO_VERSION
94
+	) {
95
+		return version_compare(
96
+			self::_effective_version($actual_core_version),
97
+			self::_effective_version($min_core_version),
98
+			'>='
99
+		);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     *    Method for registering new EE_Addons.
105
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
106
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
107
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
108
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
109
-     * 'activate_plugin', it registers the addon still, but its components are not registered
110
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
111
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
112
-     * (so that we can detect that the addon has activated on the subsequent request)
113
-     *
114
-     * @since    4.3.0
115
-     * @param string                  $addon_name                           the EE_Addon's name. Required.
116
-     * @param  array                  $setup_args                           {                                    An
117
-     *                                                                      array of arguments provided for registering
118
-     *                                                                      the message type.
119
-     * @type  string                  $class_name                           the addon's main file name.
120
-     *                                                                      If left blank, generated from the addon
121
-     *                                                                      name, changes something like "calendar" to
122
-     *                                                                      "EE_Calendar"
123
-     * @type string                   $min_core_version                     the minimum version of EE Core that the
124
-     *       addon will work with. eg "4.8.1.rc.084"
125
-     * @type string                   $version                              the "software" version for the addon. eg
126
-     *       "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress
127
-     * @type string                   $main_file_path                       the full server path to the main file
128
-     *       loaded
129
-     *                                                                      directly by WP
130
-     * @type string                   $admin_path                           full server path to the folder where the
131
-     *       addon\'s admin files reside
132
-     * @type string                   $admin_callback                       a method to be called when the EE Admin is
133
-     *       first invoked, can be used for hooking into any admin page
134
-     * @type string                   $config_section                       the section name for this addon's
135
-     *       configuration settings section (defaults to "addons")
136
-     * @type string                   $config_class                         the class name for this addon's
137
-     *       configuration settings object
138
-     * @type string                   $config_name                          the class name for this addon's
139
-     *       configuration settings object
140
-     * @type string                   $autoloader_paths                     an array of class names and the full server
141
-     *       paths to those files. Required.
142
-     * @type string                   $autoloader_folders                   an array of  "full server paths" for any
143
-     *       folders containing classes that might be invoked by the addon
144
-     * @type string                   $dms_paths                            an array of full server paths to folders
145
-     *       that contain data migration scripts. Required.
146
-     * @type string                   $module_paths                         an array of full server paths to any
147
-     *       EED_Modules used by the addon
148
-     * @type string                   $shortcode_paths                      an array of full server paths to folders
149
-     *       that contain EES_Shortcodes
150
-     * @type string                   $widget_paths                         an array of full server paths to folders
151
-     *       that contain WP_Widgets
152
-     * @type string                   $pue_options
153
-     * @type array                    $capabilities                         an array indexed by role name
154
-     *                                                                      (i.e administrator,author ) and the values
155
-     *                                                                      are an array of caps to add to the role.
156
-     *                                                                      'administrator' => array(
157
-     *                                                                      'read_addon', 'edit_addon', etc.
158
-     *                                                                      ).
159
-     * @type EE_Meta_Capability_Map[] $capability_maps                      an array of EE_Meta_Capability_Map object
160
-     *       for any addons that need to register any special meta mapped capabilities.  Should be indexed where the
161
-     *       key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class.
162
-     * @type array                    $model_paths                          array of folders containing DB models
163
-     * @see      EE_Register_Model
164
-     * @type array                    $class_paths                          array of folders containing DB classes
165
-     * @see      EE_Register_Model
166
-     * @type array                    $model_extension_paths                array of folders containing DB model
167
-     *       extensions
168
-     * @see      EE_Register_Model_Extension
169
-     * @type array                    $class_extension_paths                array of folders containing DB class
170
-     *       extensions
171
-     * @see      EE_Register_Model_Extension
172
-     * @type array message_types {
173
-     *                                                                      An array of message types with the key as
174
-     *                                                                      the message type name and the values as
175
-     *                                                                      below:
176
-     * @type string                   $mtfilename                           The filename of the message type being
177
-     *       registered. This will be the main EE_{Messagetype_Name}_message_type class.
178
-     *                                                                      (eg.
179
-     *                                                                      EE_Declined_Registration_message_type.class.php)
180
-     *                                                                      Required.
181
-     * @type array                    $autoloadpaths                        An array of paths to add to the messages
182
-     *                                                                      autoloader for the new message type.
183
-     *                                                                      Required.
184
-     * @type array                    $messengers_to_activate_with          An array of messengers that this message
185
-     *                                                                      type should activate with. Each value in
186
-     *                                                                      the
187
-     *                                                                      array
188
-     *                                                                      should match the name property of a
189
-     *                                                                      EE_messenger. Optional.
190
-     * @type array                    $messengers_to_validate_with          An array of messengers that this message
191
-     *                                                                      type should validate with. Each value in
192
-     *                                                                      the
193
-     *                                                                      array
194
-     *                                                                      should match the name property of an
195
-     *                                                                      EE_messenger.
196
-     *                                                                      Optional.
197
-     *                                                                      }
198
-     * @type array                    $custom_post_types
199
-     * @type array                    $custom_taxonomies
200
-     * @type array                    $payment_method_paths                 each element is the folder containing the
201
-     *                                                                      EE_PMT_Base child class
202
-     *                                                                      (eg,
203
-     *                                                                      '/wp-content/plugins/my_plugin/Payomatic/'
204
-     *                                                                      which contains the files
205
-     *                                                                      EE_PMT_Payomatic.pm.php)
206
-     * @type array                    $default_terms
207
-     * @type array                    $namespace                            {
208
-     *                                                                      An array with two items for registering the
209
-     *                                                                      addon's namespace. (If, for some reason,
210
-     *                                                                      you
211
-     *                                                                      require additional namespaces, use
212
-     *                                                                      EventEspresso\core\Psr4Autoloader::addNamespace()
213
-     *                                                                      directly)
214
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
215
-     * @type string                   $FQNS                                 the namespace prefix
216
-     * @type string                   $DIR                                  a base directory for class files in the
217
-     *       namespace.
218
-     *                                                                      }
219
-     *                                                                      }
220
-     * @throws EE_Error
221
-     * @return void
222
-     */
223
-    public static function register($addon_name = '', $setup_args = array())
224
-    {
225
-        // required fields MUST be present, so let's make sure they are.
226
-        \EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
227
-        // get class name for addon
228
-        $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
229
-        //setup $_settings array from incoming values.
230
-        $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
231
-        // setup PUE
232
-        \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233
-        // does this addon work with this version of core or WordPress ?
234
-        if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235
-            return;
236
-        }
237
-        // register namespaces
238
-        \EE_Register_Addon::_setup_namespaces($addon_settings);
239
-        // check if this is an activation request
240
-        if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
241
-            // dont bother setting up the rest of the addon atm
242
-            return;
243
-        }
244
-        // we need cars
245
-        \EE_Register_Addon::_setup_autoloaders($addon_name);
246
-        // register new models and extensions
247
-        \EE_Register_Addon::_register_models_and_extensions($addon_name);
248
-        // setup DMS
249
-        \EE_Register_Addon::_register_data_migration_scripts($addon_name);
250
-        // if config_class is present let's register config.
251
-        \EE_Register_Addon::_register_config($addon_name);
252
-        // register admin pages
253
-        \EE_Register_Addon::_register_admin_pages($addon_name);
254
-        // add to list of modules to be registered
255
-        \EE_Register_Addon::_register_modules($addon_name);
256
-        // add to list of shortcodes to be registered
257
-        \EE_Register_Addon::_register_shortcodes($addon_name);
258
-        // add to list of widgets to be registered
259
-        \EE_Register_Addon::_register_widgets($addon_name);
260
-        // register capability related stuff.
261
-        \EE_Register_Addon::_register_capabilities($addon_name);
262
-        // any message type to register?
263
-        \EE_Register_Addon::_register_message_types($addon_name);
264
-        // any custom post type/ custom capabilities or default terms to register
265
-        \EE_Register_Addon::_register_custom_post_types($addon_name);
266
-        // and any payment methods
267
-        \EE_Register_Addon::_register_payment_methods($addon_name);
268
-        // load and instantiate main addon class
269
-        $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
270
-        $addon->after_registration();
271
-    }
103
+	/**
104
+	 *    Method for registering new EE_Addons.
105
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
106
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
107
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
108
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
109
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
110
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
111
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
112
+	 * (so that we can detect that the addon has activated on the subsequent request)
113
+	 *
114
+	 * @since    4.3.0
115
+	 * @param string                  $addon_name                           the EE_Addon's name. Required.
116
+	 * @param  array                  $setup_args                           {                                    An
117
+	 *                                                                      array of arguments provided for registering
118
+	 *                                                                      the message type.
119
+	 * @type  string                  $class_name                           the addon's main file name.
120
+	 *                                                                      If left blank, generated from the addon
121
+	 *                                                                      name, changes something like "calendar" to
122
+	 *                                                                      "EE_Calendar"
123
+	 * @type string                   $min_core_version                     the minimum version of EE Core that the
124
+	 *       addon will work with. eg "4.8.1.rc.084"
125
+	 * @type string                   $version                              the "software" version for the addon. eg
126
+	 *       "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress
127
+	 * @type string                   $main_file_path                       the full server path to the main file
128
+	 *       loaded
129
+	 *                                                                      directly by WP
130
+	 * @type string                   $admin_path                           full server path to the folder where the
131
+	 *       addon\'s admin files reside
132
+	 * @type string                   $admin_callback                       a method to be called when the EE Admin is
133
+	 *       first invoked, can be used for hooking into any admin page
134
+	 * @type string                   $config_section                       the section name for this addon's
135
+	 *       configuration settings section (defaults to "addons")
136
+	 * @type string                   $config_class                         the class name for this addon's
137
+	 *       configuration settings object
138
+	 * @type string                   $config_name                          the class name for this addon's
139
+	 *       configuration settings object
140
+	 * @type string                   $autoloader_paths                     an array of class names and the full server
141
+	 *       paths to those files. Required.
142
+	 * @type string                   $autoloader_folders                   an array of  "full server paths" for any
143
+	 *       folders containing classes that might be invoked by the addon
144
+	 * @type string                   $dms_paths                            an array of full server paths to folders
145
+	 *       that contain data migration scripts. Required.
146
+	 * @type string                   $module_paths                         an array of full server paths to any
147
+	 *       EED_Modules used by the addon
148
+	 * @type string                   $shortcode_paths                      an array of full server paths to folders
149
+	 *       that contain EES_Shortcodes
150
+	 * @type string                   $widget_paths                         an array of full server paths to folders
151
+	 *       that contain WP_Widgets
152
+	 * @type string                   $pue_options
153
+	 * @type array                    $capabilities                         an array indexed by role name
154
+	 *                                                                      (i.e administrator,author ) and the values
155
+	 *                                                                      are an array of caps to add to the role.
156
+	 *                                                                      'administrator' => array(
157
+	 *                                                                      'read_addon', 'edit_addon', etc.
158
+	 *                                                                      ).
159
+	 * @type EE_Meta_Capability_Map[] $capability_maps                      an array of EE_Meta_Capability_Map object
160
+	 *       for any addons that need to register any special meta mapped capabilities.  Should be indexed where the
161
+	 *       key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class.
162
+	 * @type array                    $model_paths                          array of folders containing DB models
163
+	 * @see      EE_Register_Model
164
+	 * @type array                    $class_paths                          array of folders containing DB classes
165
+	 * @see      EE_Register_Model
166
+	 * @type array                    $model_extension_paths                array of folders containing DB model
167
+	 *       extensions
168
+	 * @see      EE_Register_Model_Extension
169
+	 * @type array                    $class_extension_paths                array of folders containing DB class
170
+	 *       extensions
171
+	 * @see      EE_Register_Model_Extension
172
+	 * @type array message_types {
173
+	 *                                                                      An array of message types with the key as
174
+	 *                                                                      the message type name and the values as
175
+	 *                                                                      below:
176
+	 * @type string                   $mtfilename                           The filename of the message type being
177
+	 *       registered. This will be the main EE_{Messagetype_Name}_message_type class.
178
+	 *                                                                      (eg.
179
+	 *                                                                      EE_Declined_Registration_message_type.class.php)
180
+	 *                                                                      Required.
181
+	 * @type array                    $autoloadpaths                        An array of paths to add to the messages
182
+	 *                                                                      autoloader for the new message type.
183
+	 *                                                                      Required.
184
+	 * @type array                    $messengers_to_activate_with          An array of messengers that this message
185
+	 *                                                                      type should activate with. Each value in
186
+	 *                                                                      the
187
+	 *                                                                      array
188
+	 *                                                                      should match the name property of a
189
+	 *                                                                      EE_messenger. Optional.
190
+	 * @type array                    $messengers_to_validate_with          An array of messengers that this message
191
+	 *                                                                      type should validate with. Each value in
192
+	 *                                                                      the
193
+	 *                                                                      array
194
+	 *                                                                      should match the name property of an
195
+	 *                                                                      EE_messenger.
196
+	 *                                                                      Optional.
197
+	 *                                                                      }
198
+	 * @type array                    $custom_post_types
199
+	 * @type array                    $custom_taxonomies
200
+	 * @type array                    $payment_method_paths                 each element is the folder containing the
201
+	 *                                                                      EE_PMT_Base child class
202
+	 *                                                                      (eg,
203
+	 *                                                                      '/wp-content/plugins/my_plugin/Payomatic/'
204
+	 *                                                                      which contains the files
205
+	 *                                                                      EE_PMT_Payomatic.pm.php)
206
+	 * @type array                    $default_terms
207
+	 * @type array                    $namespace                            {
208
+	 *                                                                      An array with two items for registering the
209
+	 *                                                                      addon's namespace. (If, for some reason,
210
+	 *                                                                      you
211
+	 *                                                                      require additional namespaces, use
212
+	 *                                                                      EventEspresso\core\Psr4Autoloader::addNamespace()
213
+	 *                                                                      directly)
214
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
215
+	 * @type string                   $FQNS                                 the namespace prefix
216
+	 * @type string                   $DIR                                  a base directory for class files in the
217
+	 *       namespace.
218
+	 *                                                                      }
219
+	 *                                                                      }
220
+	 * @throws EE_Error
221
+	 * @return void
222
+	 */
223
+	public static function register($addon_name = '', $setup_args = array())
224
+	{
225
+		// required fields MUST be present, so let's make sure they are.
226
+		\EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
227
+		// get class name for addon
228
+		$class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
229
+		//setup $_settings array from incoming values.
230
+		$addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
231
+		// setup PUE
232
+		\EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233
+		// does this addon work with this version of core or WordPress ?
234
+		if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235
+			return;
236
+		}
237
+		// register namespaces
238
+		\EE_Register_Addon::_setup_namespaces($addon_settings);
239
+		// check if this is an activation request
240
+		if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
241
+			// dont bother setting up the rest of the addon atm
242
+			return;
243
+		}
244
+		// we need cars
245
+		\EE_Register_Addon::_setup_autoloaders($addon_name);
246
+		// register new models and extensions
247
+		\EE_Register_Addon::_register_models_and_extensions($addon_name);
248
+		// setup DMS
249
+		\EE_Register_Addon::_register_data_migration_scripts($addon_name);
250
+		// if config_class is present let's register config.
251
+		\EE_Register_Addon::_register_config($addon_name);
252
+		// register admin pages
253
+		\EE_Register_Addon::_register_admin_pages($addon_name);
254
+		// add to list of modules to be registered
255
+		\EE_Register_Addon::_register_modules($addon_name);
256
+		// add to list of shortcodes to be registered
257
+		\EE_Register_Addon::_register_shortcodes($addon_name);
258
+		// add to list of widgets to be registered
259
+		\EE_Register_Addon::_register_widgets($addon_name);
260
+		// register capability related stuff.
261
+		\EE_Register_Addon::_register_capabilities($addon_name);
262
+		// any message type to register?
263
+		\EE_Register_Addon::_register_message_types($addon_name);
264
+		// any custom post type/ custom capabilities or default terms to register
265
+		\EE_Register_Addon::_register_custom_post_types($addon_name);
266
+		// and any payment methods
267
+		\EE_Register_Addon::_register_payment_methods($addon_name);
268
+		// load and instantiate main addon class
269
+		$addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
270
+		$addon->after_registration();
271
+	}
272 272
 
273 273
 
274
-    /**
275
-     * @param string $addon_name
276
-     * @param array  $setup_args
277
-     * @return void
278
-     * @throws \EE_Error
279
-     */
280
-    private static function _verify_parameters($addon_name, array $setup_args)
281
-    {
282
-        // required fields MUST be present, so let's make sure they are.
283
-        if (empty($addon_name) || ! is_array($setup_args)) {
284
-            throw new EE_Error(
285
-                __(
286
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
287
-                    'event_espresso'
288
-                )
289
-            );
290
-        }
291
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292
-            throw new EE_Error(
293
-                sprintf(
294
-                    __(
295
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
296
-                        'event_espresso'
297
-                    ),
298
-                    implode(',', array_keys($setup_args))
299
-                )
300
-            );
301
-        }
302
-        // check that addon has not already been registered with that name
303
-        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
304
-            throw new EE_Error(
305
-                sprintf(
306
-                    __(
307
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
308
-                        'event_espresso'
309
-                    ),
310
-                    $addon_name
311
-                )
312
-            );
313
-        }
314
-    }
274
+	/**
275
+	 * @param string $addon_name
276
+	 * @param array  $setup_args
277
+	 * @return void
278
+	 * @throws \EE_Error
279
+	 */
280
+	private static function _verify_parameters($addon_name, array $setup_args)
281
+	{
282
+		// required fields MUST be present, so let's make sure they are.
283
+		if (empty($addon_name) || ! is_array($setup_args)) {
284
+			throw new EE_Error(
285
+				__(
286
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
287
+					'event_espresso'
288
+				)
289
+			);
290
+		}
291
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292
+			throw new EE_Error(
293
+				sprintf(
294
+					__(
295
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
296
+						'event_espresso'
297
+					),
298
+					implode(',', array_keys($setup_args))
299
+				)
300
+			);
301
+		}
302
+		// check that addon has not already been registered with that name
303
+		if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
304
+			throw new EE_Error(
305
+				sprintf(
306
+					__(
307
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
308
+						'event_espresso'
309
+					),
310
+					$addon_name
311
+				)
312
+			);
313
+		}
314
+	}
315 315
 
316 316
 
317
-    /**
318
-     * @param string $addon_name
319
-     * @param array  $setup_args
320
-     * @return string
321
-     */
322
-    private static function _parse_class_name($addon_name, array $setup_args)
323
-    {
324
-        if (empty($setup_args['class_name'])) {
325
-            // generate one by first separating name with spaces
326
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
327
-            //capitalize, then replace spaces with underscores
328
-            $class_name = str_replace(' ', '_', ucwords($class_name));
329
-        } else {
330
-            $class_name = $setup_args['class_name'];
331
-        }
332
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
333
-    }
317
+	/**
318
+	 * @param string $addon_name
319
+	 * @param array  $setup_args
320
+	 * @return string
321
+	 */
322
+	private static function _parse_class_name($addon_name, array $setup_args)
323
+	{
324
+		if (empty($setup_args['class_name'])) {
325
+			// generate one by first separating name with spaces
326
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
327
+			//capitalize, then replace spaces with underscores
328
+			$class_name = str_replace(' ', '_', ucwords($class_name));
329
+		} else {
330
+			$class_name = $setup_args['class_name'];
331
+		}
332
+		return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
333
+	}
334 334
 
335 335
 
336
-    /**
337
-     * @param string $class_name
338
-     * @param array  $setup_args
339
-     * @return array
340
-     */
341
-    private static function _get_addon_settings($class_name, array $setup_args)
342
-    {
343
-        //setup $_settings array from incoming values.
344
-        $addon_settings = array(
345
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
346
-            'class_name'            => $class_name,
347
-            // the addon slug for use in URLs, etc
348
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
349
-                ? (string)$setup_args['plugin_slug']
350
-                : '',
351
-            // page slug to be used when generating the "Settings" link on the WP plugin page
352
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
-                ? (string)$setup_args['plugin_action_slug']
354
-                : '',
355
-            // the "software" version for the addon
356
-            'version'               => isset($setup_args['version'])
357
-                ? (string)$setup_args['version']
358
-                : '',
359
-            // the minimum version of EE Core that the addon will work with
360
-            'min_core_version'      => isset($setup_args['min_core_version'])
361
-                ? (string)$setup_args['min_core_version']
362
-                : '',
363
-            // the minimum version of WordPress that the addon will work with
364
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
365
-                ? (string)$setup_args['min_wp_version']
366
-                : EE_MIN_WP_VER_REQUIRED,
367
-            // full server path to main file (file loaded directly by WP)
368
-            'main_file_path'        => isset($setup_args['main_file_path'])
369
-                ? (string)$setup_args['main_file_path']
370
-                : '',
371
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372
-            'admin_path'            => isset($setup_args['admin_path'])
373
-                ? (string)$setup_args['admin_path'] : '',
374
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375
-            'admin_callback'        => isset($setup_args['admin_callback'])
376
-                ? (string)$setup_args['admin_callback']
377
-                : '',
378
-            // the section name for this addon's configuration settings section (defaults to "addons")
379
-            'config_section'        => isset($setup_args['config_section'])
380
-                ? (string)$setup_args['config_section']
381
-                : 'addons',
382
-            // the class name for this addon's configuration settings object
383
-            'config_class'          => isset($setup_args['config_class'])
384
-                ? (string)$setup_args['config_class'] : '',
385
-            //the name given to the config for this addons' configuration settings object (optional)
386
-            'config_name'           => isset($setup_args['config_name'])
387
-                ? (string)$setup_args['config_name'] : '',
388
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
-                ? (array)$setup_args['autoloader_paths']
391
-                : array(),
392
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
-                ? (array)$setup_args['autoloader_folders']
395
-                : array(),
396
-            // array of full server paths to any EE_DMS data migration scripts used by the addon
397
-            'dms_paths'             => isset($setup_args['dms_paths'])
398
-                ? (array)$setup_args['dms_paths']
399
-                : array(),
400
-            // array of full server paths to any EED_Modules used by the addon
401
-            'module_paths'          => isset($setup_args['module_paths'])
402
-                ? (array)$setup_args['module_paths']
403
-                : array(),
404
-            // array of full server paths to any EES_Shortcodes used by the addon
405
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
-                ? (array)$setup_args['shortcode_paths']
407
-                : array(),
408
-            'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
409
-                ? (array) $setup_args['shortcode_fqcns']
410
-                : array(),
411
-            // array of full server paths to any WP_Widgets used by the addon
412
-            'widget_paths'          => isset($setup_args['widget_paths'])
413
-                ? (array)$setup_args['widget_paths']
414
-                : array(),
415
-            // array of PUE options used by the addon
416
-            'pue_options'           => isset($setup_args['pue_options'])
417
-                ? (array)$setup_args['pue_options']
418
-                : array(),
419
-            'message_types'         => isset($setup_args['message_types'])
420
-                ? (array)$setup_args['message_types']
421
-                : array(),
422
-            'capabilities'          => isset($setup_args['capabilities'])
423
-                ? (array)$setup_args['capabilities']
424
-                : array(),
425
-            'capability_maps'       => isset($setup_args['capability_maps'])
426
-                ? (array)$setup_args['capability_maps']
427
-                : array(),
428
-            'model_paths'           => isset($setup_args['model_paths'])
429
-                ? (array)$setup_args['model_paths']
430
-                : array(),
431
-            'class_paths'           => isset($setup_args['class_paths'])
432
-                ? (array)$setup_args['class_paths']
433
-                : array(),
434
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
435
-                ? (array)$setup_args['model_extension_paths']
436
-                : array(),
437
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
438
-                ? (array)$setup_args['class_extension_paths']
439
-                : array(),
440
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
441
-                ? (array)$setup_args['custom_post_types']
442
-                : array(),
443
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
444
-                ? (array)$setup_args['custom_taxonomies']
445
-                : array(),
446
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
447
-                ? (array)$setup_args['payment_method_paths']
448
-                : array(),
449
-            'default_terms'         => isset($setup_args['default_terms'])
450
-                ? (array)$setup_args['default_terms']
451
-                : array(),
452
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
453
-            // that can be used for adding upgrading/marketing info
454
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
455
-                ? $setup_args['plugins_page_row']
456
-                : '',
457
-            'namespace'             => isset(
458
-                $setup_args['namespace'],
459
-                $setup_args['namespace']['FQNS'],
460
-                $setup_args['namespace']['DIR']
461
-            )
462
-                ? (array)$setup_args['namespace']
463
-                : array(),
464
-        );
465
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
466
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
467
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
468
-                                                && ! empty($addon_settings['admin_path'])
469
-            ? $addon_settings['plugin_slug']
470
-            : $addon_settings['plugin_action_slug'];
471
-        // full server path to main file (file loaded directly by WP)
472
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
473
-        return $addon_settings;
474
-    }
336
+	/**
337
+	 * @param string $class_name
338
+	 * @param array  $setup_args
339
+	 * @return array
340
+	 */
341
+	private static function _get_addon_settings($class_name, array $setup_args)
342
+	{
343
+		//setup $_settings array from incoming values.
344
+		$addon_settings = array(
345
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
346
+			'class_name'            => $class_name,
347
+			// the addon slug for use in URLs, etc
348
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
349
+				? (string)$setup_args['plugin_slug']
350
+				: '',
351
+			// page slug to be used when generating the "Settings" link on the WP plugin page
352
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
+				? (string)$setup_args['plugin_action_slug']
354
+				: '',
355
+			// the "software" version for the addon
356
+			'version'               => isset($setup_args['version'])
357
+				? (string)$setup_args['version']
358
+				: '',
359
+			// the minimum version of EE Core that the addon will work with
360
+			'min_core_version'      => isset($setup_args['min_core_version'])
361
+				? (string)$setup_args['min_core_version']
362
+				: '',
363
+			// the minimum version of WordPress that the addon will work with
364
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
365
+				? (string)$setup_args['min_wp_version']
366
+				: EE_MIN_WP_VER_REQUIRED,
367
+			// full server path to main file (file loaded directly by WP)
368
+			'main_file_path'        => isset($setup_args['main_file_path'])
369
+				? (string)$setup_args['main_file_path']
370
+				: '',
371
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372
+			'admin_path'            => isset($setup_args['admin_path'])
373
+				? (string)$setup_args['admin_path'] : '',
374
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375
+			'admin_callback'        => isset($setup_args['admin_callback'])
376
+				? (string)$setup_args['admin_callback']
377
+				: '',
378
+			// the section name for this addon's configuration settings section (defaults to "addons")
379
+			'config_section'        => isset($setup_args['config_section'])
380
+				? (string)$setup_args['config_section']
381
+				: 'addons',
382
+			// the class name for this addon's configuration settings object
383
+			'config_class'          => isset($setup_args['config_class'])
384
+				? (string)$setup_args['config_class'] : '',
385
+			//the name given to the config for this addons' configuration settings object (optional)
386
+			'config_name'           => isset($setup_args['config_name'])
387
+				? (string)$setup_args['config_name'] : '',
388
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
+				? (array)$setup_args['autoloader_paths']
391
+				: array(),
392
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
+				? (array)$setup_args['autoloader_folders']
395
+				: array(),
396
+			// array of full server paths to any EE_DMS data migration scripts used by the addon
397
+			'dms_paths'             => isset($setup_args['dms_paths'])
398
+				? (array)$setup_args['dms_paths']
399
+				: array(),
400
+			// array of full server paths to any EED_Modules used by the addon
401
+			'module_paths'          => isset($setup_args['module_paths'])
402
+				? (array)$setup_args['module_paths']
403
+				: array(),
404
+			// array of full server paths to any EES_Shortcodes used by the addon
405
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
+				? (array)$setup_args['shortcode_paths']
407
+				: array(),
408
+			'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
409
+				? (array) $setup_args['shortcode_fqcns']
410
+				: array(),
411
+			// array of full server paths to any WP_Widgets used by the addon
412
+			'widget_paths'          => isset($setup_args['widget_paths'])
413
+				? (array)$setup_args['widget_paths']
414
+				: array(),
415
+			// array of PUE options used by the addon
416
+			'pue_options'           => isset($setup_args['pue_options'])
417
+				? (array)$setup_args['pue_options']
418
+				: array(),
419
+			'message_types'         => isset($setup_args['message_types'])
420
+				? (array)$setup_args['message_types']
421
+				: array(),
422
+			'capabilities'          => isset($setup_args['capabilities'])
423
+				? (array)$setup_args['capabilities']
424
+				: array(),
425
+			'capability_maps'       => isset($setup_args['capability_maps'])
426
+				? (array)$setup_args['capability_maps']
427
+				: array(),
428
+			'model_paths'           => isset($setup_args['model_paths'])
429
+				? (array)$setup_args['model_paths']
430
+				: array(),
431
+			'class_paths'           => isset($setup_args['class_paths'])
432
+				? (array)$setup_args['class_paths']
433
+				: array(),
434
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
435
+				? (array)$setup_args['model_extension_paths']
436
+				: array(),
437
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
438
+				? (array)$setup_args['class_extension_paths']
439
+				: array(),
440
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
441
+				? (array)$setup_args['custom_post_types']
442
+				: array(),
443
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
444
+				? (array)$setup_args['custom_taxonomies']
445
+				: array(),
446
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
447
+				? (array)$setup_args['payment_method_paths']
448
+				: array(),
449
+			'default_terms'         => isset($setup_args['default_terms'])
450
+				? (array)$setup_args['default_terms']
451
+				: array(),
452
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
453
+			// that can be used for adding upgrading/marketing info
454
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
455
+				? $setup_args['plugins_page_row']
456
+				: '',
457
+			'namespace'             => isset(
458
+				$setup_args['namespace'],
459
+				$setup_args['namespace']['FQNS'],
460
+				$setup_args['namespace']['DIR']
461
+			)
462
+				? (array)$setup_args['namespace']
463
+				: array(),
464
+		);
465
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
466
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
467
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
468
+												&& ! empty($addon_settings['admin_path'])
469
+			? $addon_settings['plugin_slug']
470
+			: $addon_settings['plugin_action_slug'];
471
+		// full server path to main file (file loaded directly by WP)
472
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
473
+		return $addon_settings;
474
+	}
475 475
 
476 476
 
477
-    /**
478
-     * @param string $addon_name
479
-     * @param array  $addon_settings
480
-     * @return boolean
481
-     */
482
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
483
-    {
484
-        global $wp_version;
485
-        $incompatibility_message = '';
486
-        //check whether this addon version is compatible with EE core
487
-        if (
488
-            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
489
-            && ! self::_meets_min_core_version_requirement(
490
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
491
-                $addon_settings['version']
492
-            )
493
-        ) {
494
-            $incompatibility_message = sprintf(
495
-                __(
496
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
497
-                ),
498
-                $addon_name,
499
-                '<br />',
500
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
501
-                '<span style="font-weight: bold; color: #D54E21;">',
502
-                '</span><br />'
503
-            );
504
-        } else if (
505
-        ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
506
-        ) {
507
-            $incompatibility_message = sprintf(
508
-                __(
509
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
510
-                    'event_espresso'
511
-                ),
512
-                $addon_name,
513
-                self::_effective_version($addon_settings['min_core_version']),
514
-                self::_effective_version(espresso_version()),
515
-                '<br />',
516
-                '<span style="font-weight: bold; color: #D54E21;">',
517
-                '</span><br />'
518
-            );
519
-        } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
520
-            $incompatibility_message = sprintf(
521
-                __(
522
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
523
-                    'event_espresso'
524
-                ),
525
-                $addon_name,
526
-                $addon_settings['min_wp_version'],
527
-                '<br />',
528
-                '<span style="font-weight: bold; color: #D54E21;">',
529
-                '</span><br />'
530
-            );
531
-        }
532
-        if (! empty($incompatibility_message)) {
533
-            // remove 'activate' from the REQUEST
534
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
535
-            unset($_GET['activate'], $_REQUEST['activate']);
536
-            if (current_user_can('activate_plugins')) {
537
-                // show an error message indicating the plugin didn't activate properly
538
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
539
-            }
540
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
541
-            return false;
542
-        }
543
-        // addon IS compatible
544
-        return true;
545
-    }
477
+	/**
478
+	 * @param string $addon_name
479
+	 * @param array  $addon_settings
480
+	 * @return boolean
481
+	 */
482
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
483
+	{
484
+		global $wp_version;
485
+		$incompatibility_message = '';
486
+		//check whether this addon version is compatible with EE core
487
+		if (
488
+			isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
489
+			&& ! self::_meets_min_core_version_requirement(
490
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
491
+				$addon_settings['version']
492
+			)
493
+		) {
494
+			$incompatibility_message = sprintf(
495
+				__(
496
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
497
+				),
498
+				$addon_name,
499
+				'<br />',
500
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
501
+				'<span style="font-weight: bold; color: #D54E21;">',
502
+				'</span><br />'
503
+			);
504
+		} else if (
505
+		! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
506
+		) {
507
+			$incompatibility_message = sprintf(
508
+				__(
509
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
510
+					'event_espresso'
511
+				),
512
+				$addon_name,
513
+				self::_effective_version($addon_settings['min_core_version']),
514
+				self::_effective_version(espresso_version()),
515
+				'<br />',
516
+				'<span style="font-weight: bold; color: #D54E21;">',
517
+				'</span><br />'
518
+			);
519
+		} else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
520
+			$incompatibility_message = sprintf(
521
+				__(
522
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
523
+					'event_espresso'
524
+				),
525
+				$addon_name,
526
+				$addon_settings['min_wp_version'],
527
+				'<br />',
528
+				'<span style="font-weight: bold; color: #D54E21;">',
529
+				'</span><br />'
530
+			);
531
+		}
532
+		if (! empty($incompatibility_message)) {
533
+			// remove 'activate' from the REQUEST
534
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
535
+			unset($_GET['activate'], $_REQUEST['activate']);
536
+			if (current_user_can('activate_plugins')) {
537
+				// show an error message indicating the plugin didn't activate properly
538
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
539
+			}
540
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
541
+			return false;
542
+		}
543
+		// addon IS compatible
544
+		return true;
545
+	}
546 546
 
547 547
 
548
-    /**
549
-     * if plugin update engine is being used for auto-updates,
550
-     * then let's set that up now before going any further so that ALL addons can be updated
551
-     * (not needed if PUE is not being used)
552
-     *
553
-     * @param string $addon_name
554
-     * @param string $class_name
555
-     * @param array  $setup_args
556
-     * @return void
557
-     */
558
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
559
-    {
560
-        if (! empty($setup_args['pue_options'])) {
561
-            self::$_settings[$addon_name]['pue_options'] = array(
562
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
563
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
564
-                    : 'espresso_' . strtolower($class_name),
565
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
566
-                    ? (string)$setup_args['pue_options']['plugin_basename']
567
-                    : plugin_basename($setup_args['main_file_path']),
568
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
569
-                    ? (string)$setup_args['pue_options']['checkPeriod']
570
-                    : '24',
571
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
572
-                    ? (string)$setup_args['pue_options']['use_wp_update']
573
-                    : false,
574
-            );
575
-            add_action(
576
-                'AHEE__EE_System__brew_espresso__after_pue_init',
577
-                array('EE_Register_Addon', 'load_pue_update')
578
-            );
579
-        }
580
-    }
548
+	/**
549
+	 * if plugin update engine is being used for auto-updates,
550
+	 * then let's set that up now before going any further so that ALL addons can be updated
551
+	 * (not needed if PUE is not being used)
552
+	 *
553
+	 * @param string $addon_name
554
+	 * @param string $class_name
555
+	 * @param array  $setup_args
556
+	 * @return void
557
+	 */
558
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
559
+	{
560
+		if (! empty($setup_args['pue_options'])) {
561
+			self::$_settings[$addon_name]['pue_options'] = array(
562
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
563
+					? (string)$setup_args['pue_options']['pue_plugin_slug']
564
+					: 'espresso_' . strtolower($class_name),
565
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
566
+					? (string)$setup_args['pue_options']['plugin_basename']
567
+					: plugin_basename($setup_args['main_file_path']),
568
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
569
+					? (string)$setup_args['pue_options']['checkPeriod']
570
+					: '24',
571
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
572
+					? (string)$setup_args['pue_options']['use_wp_update']
573
+					: false,
574
+			);
575
+			add_action(
576
+				'AHEE__EE_System__brew_espresso__after_pue_init',
577
+				array('EE_Register_Addon', 'load_pue_update')
578
+			);
579
+		}
580
+	}
581 581
 
582 582
 
583
-    /**
584
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
585
-     *
586
-     * @param array $addon_settings
587
-     * @return void
588
-     */
589
-    private static function _setup_namespaces(array $addon_settings)
590
-    {
591
-        //
592
-        if (
593
-        isset(
594
-            $addon_settings['namespace'],
595
-            $addon_settings['namespace']['FQNS'],
596
-            $addon_settings['namespace']['DIR']
597
-        )
598
-        ) {
599
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
600
-                $addon_settings['namespace']['FQNS'],
601
-                $addon_settings['namespace']['DIR']
602
-            );
603
-        }
604
-    }
583
+	/**
584
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
585
+	 *
586
+	 * @param array $addon_settings
587
+	 * @return void
588
+	 */
589
+	private static function _setup_namespaces(array $addon_settings)
590
+	{
591
+		//
592
+		if (
593
+		isset(
594
+			$addon_settings['namespace'],
595
+			$addon_settings['namespace']['FQNS'],
596
+			$addon_settings['namespace']['DIR']
597
+		)
598
+		) {
599
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
600
+				$addon_settings['namespace']['FQNS'],
601
+				$addon_settings['namespace']['DIR']
602
+			);
603
+		}
604
+	}
605 605
 
606 606
 
607
-    /**
608
-     * @param string $addon_name
609
-     * @param array  $addon_settings
610
-     * @return bool
611
-     */
612
-    private static function _addon_activation($addon_name, array $addon_settings)
613
-    {
614
-        // this is an activation request
615
-        if (did_action('activate_plugin')) {
616
-            //to find if THIS is the addon that was activated, just check if we have already registered it or not
617
-            //(as the newly-activated addon wasn't around the first time addons were registered).
618
-            //Note: the presence of pue_options in the addon registration options will initialize the $_settings
619
-            //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
620
-            if (! isset(self::$_settings[$addon_name])
621
-                || (isset(self::$_settings[$addon_name])
622
-                    && ! isset(self::$_settings[$addon_name]['class_name'])
623
-                )
624
-            ) {
625
-                self::$_settings[$addon_name] = $addon_settings;
626
-                $addon                        = self::_load_and_init_addon_class($addon_name);
627
-                $addon->set_activation_indicator_option();
628
-                // dont bother setting up the rest of the addon.
629
-                // we know it was just activated and the request will end soon
630
-            }
631
-            return true;
632
-        }
633
-        // make sure this was called in the right place!
634
-        if (
635
-            ! did_action('AHEE__EE_System__load_espresso_addons')
636
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
637
-        ) {
638
-            EE_Error::doing_it_wrong(
639
-                __METHOD__,
640
-                sprintf(
641
-                    __(
642
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
643
-                        'event_espresso'
644
-                    ),
645
-                    $addon_name
646
-                ),
647
-                '4.3.0'
648
-            );
649
-        }
650
-        // make sure addon settings are set correctly without overwriting anything existing
651
-        if (isset(self::$_settings[$addon_name])) {
652
-            self::$_settings[$addon_name] += $addon_settings;
653
-        } else {
654
-            self::$_settings[$addon_name] = $addon_settings;
655
-        }
656
-        return false;
657
-    }
607
+	/**
608
+	 * @param string $addon_name
609
+	 * @param array  $addon_settings
610
+	 * @return bool
611
+	 */
612
+	private static function _addon_activation($addon_name, array $addon_settings)
613
+	{
614
+		// this is an activation request
615
+		if (did_action('activate_plugin')) {
616
+			//to find if THIS is the addon that was activated, just check if we have already registered it or not
617
+			//(as the newly-activated addon wasn't around the first time addons were registered).
618
+			//Note: the presence of pue_options in the addon registration options will initialize the $_settings
619
+			//property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
620
+			if (! isset(self::$_settings[$addon_name])
621
+				|| (isset(self::$_settings[$addon_name])
622
+					&& ! isset(self::$_settings[$addon_name]['class_name'])
623
+				)
624
+			) {
625
+				self::$_settings[$addon_name] = $addon_settings;
626
+				$addon                        = self::_load_and_init_addon_class($addon_name);
627
+				$addon->set_activation_indicator_option();
628
+				// dont bother setting up the rest of the addon.
629
+				// we know it was just activated and the request will end soon
630
+			}
631
+			return true;
632
+		}
633
+		// make sure this was called in the right place!
634
+		if (
635
+			! did_action('AHEE__EE_System__load_espresso_addons')
636
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
637
+		) {
638
+			EE_Error::doing_it_wrong(
639
+				__METHOD__,
640
+				sprintf(
641
+					__(
642
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
643
+						'event_espresso'
644
+					),
645
+					$addon_name
646
+				),
647
+				'4.3.0'
648
+			);
649
+		}
650
+		// make sure addon settings are set correctly without overwriting anything existing
651
+		if (isset(self::$_settings[$addon_name])) {
652
+			self::$_settings[$addon_name] += $addon_settings;
653
+		} else {
654
+			self::$_settings[$addon_name] = $addon_settings;
655
+		}
656
+		return false;
657
+	}
658 658
 
659 659
 
660
-    /**
661
-     * @param string $addon_name
662
-     * @return void
663
-     * @throws \EE_Error
664
-     */
665
-    private static function _setup_autoloaders($addon_name)
666
-    {
667
-        if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
668
-            // setup autoloader for single file
669
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
670
-        }
671
-        // setup autoloaders for folders
672
-        if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
674
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
675
-            }
676
-        }
677
-    }
660
+	/**
661
+	 * @param string $addon_name
662
+	 * @return void
663
+	 * @throws \EE_Error
664
+	 */
665
+	private static function _setup_autoloaders($addon_name)
666
+	{
667
+		if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
668
+			// setup autoloader for single file
669
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
670
+		}
671
+		// setup autoloaders for folders
672
+		if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
+			foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
674
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
675
+			}
676
+		}
677
+	}
678 678
 
679 679
 
680
-    /**
681
-     * register new models and extensions
682
-     *
683
-     * @param string $addon_name
684
-     * @return void
685
-     * @throws \EE_Error
686
-     */
687
-    private static function _register_models_and_extensions($addon_name)
688
-    {
689
-        // register new models
690
-        if (
691
-            ! empty(self::$_settings[$addon_name]['model_paths'])
692
-            || ! empty(self::$_settings[$addon_name]['class_paths'])
693
-        ) {
694
-            EE_Register_Model::register(
695
-                $addon_name,
696
-                array(
697
-                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
698
-                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
699
-                )
700
-            );
701
-        }
702
-        // register model extensions
703
-        if (
704
-            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
705
-            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
706
-        ) {
707
-            EE_Register_Model_Extensions::register(
708
-                $addon_name,
709
-                array(
710
-                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
711
-                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
712
-                )
713
-            );
714
-        }
715
-    }
680
+	/**
681
+	 * register new models and extensions
682
+	 *
683
+	 * @param string $addon_name
684
+	 * @return void
685
+	 * @throws \EE_Error
686
+	 */
687
+	private static function _register_models_and_extensions($addon_name)
688
+	{
689
+		// register new models
690
+		if (
691
+			! empty(self::$_settings[$addon_name]['model_paths'])
692
+			|| ! empty(self::$_settings[$addon_name]['class_paths'])
693
+		) {
694
+			EE_Register_Model::register(
695
+				$addon_name,
696
+				array(
697
+					'model_paths' => self::$_settings[$addon_name]['model_paths'],
698
+					'class_paths' => self::$_settings[$addon_name]['class_paths'],
699
+				)
700
+			);
701
+		}
702
+		// register model extensions
703
+		if (
704
+			! empty(self::$_settings[$addon_name]['model_extension_paths'])
705
+			|| ! empty(self::$_settings[$addon_name]['class_extension_paths'])
706
+		) {
707
+			EE_Register_Model_Extensions::register(
708
+				$addon_name,
709
+				array(
710
+					'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
711
+					'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
712
+				)
713
+			);
714
+		}
715
+	}
716 716
 
717 717
 
718
-    /**
719
-     * @param string $addon_name
720
-     * @return void
721
-     * @throws \EE_Error
722
-     */
723
-    private static function _register_data_migration_scripts($addon_name)
724
-    {
725
-        // setup DMS
726
-        if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
727
-            EE_Register_Data_Migration_Scripts::register(
728
-                $addon_name,
729
-                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
730
-            );
731
-        }
732
-    }
718
+	/**
719
+	 * @param string $addon_name
720
+	 * @return void
721
+	 * @throws \EE_Error
722
+	 */
723
+	private static function _register_data_migration_scripts($addon_name)
724
+	{
725
+		// setup DMS
726
+		if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
727
+			EE_Register_Data_Migration_Scripts::register(
728
+				$addon_name,
729
+				array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
730
+			);
731
+		}
732
+	}
733 733
 
734 734
 
735
-    /**
736
-     * @param string $addon_name
737
-     * @return void
738
-     * @throws \EE_Error
739
-     */
740
-    private static function _register_config($addon_name)
741
-    {
742
-        // if config_class is present let's register config.
743
-        if (! empty(self::$_settings[$addon_name]['config_class'])) {
744
-            EE_Register_Config::register(
745
-                self::$_settings[$addon_name]['config_class'],
746
-                array(
747
-                    'config_section' => self::$_settings[$addon_name]['config_section'],
748
-                    'config_name'    => self::$_settings[$addon_name]['config_name'],
749
-                )
750
-            );
751
-        }
752
-    }
735
+	/**
736
+	 * @param string $addon_name
737
+	 * @return void
738
+	 * @throws \EE_Error
739
+	 */
740
+	private static function _register_config($addon_name)
741
+	{
742
+		// if config_class is present let's register config.
743
+		if (! empty(self::$_settings[$addon_name]['config_class'])) {
744
+			EE_Register_Config::register(
745
+				self::$_settings[$addon_name]['config_class'],
746
+				array(
747
+					'config_section' => self::$_settings[$addon_name]['config_section'],
748
+					'config_name'    => self::$_settings[$addon_name]['config_name'],
749
+				)
750
+			);
751
+		}
752
+	}
753 753
 
754 754
 
755
-    /**
756
-     * @param string $addon_name
757
-     * @return void
758
-     * @throws \EE_Error
759
-     */
760
-    private static function _register_admin_pages($addon_name)
761
-    {
762
-        if (! empty(self::$_settings[$addon_name]['admin_path'])) {
763
-            EE_Register_Admin_Page::register(
764
-                $addon_name,
765
-                array('page_path' => self::$_settings[$addon_name]['admin_path'])
766
-            );
767
-        }
768
-    }
755
+	/**
756
+	 * @param string $addon_name
757
+	 * @return void
758
+	 * @throws \EE_Error
759
+	 */
760
+	private static function _register_admin_pages($addon_name)
761
+	{
762
+		if (! empty(self::$_settings[$addon_name]['admin_path'])) {
763
+			EE_Register_Admin_Page::register(
764
+				$addon_name,
765
+				array('page_path' => self::$_settings[$addon_name]['admin_path'])
766
+			);
767
+		}
768
+	}
769 769
 
770 770
 
771
-    /**
772
-     * @param string $addon_name
773
-     * @return void
774
-     * @throws \EE_Error
775
-     */
776
-    private static function _register_modules($addon_name)
777
-    {
778
-        if (! empty(self::$_settings[$addon_name]['module_paths'])) {
779
-            EE_Register_Module::register(
780
-                $addon_name,
781
-                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
782
-            );
783
-        }
784
-    }
771
+	/**
772
+	 * @param string $addon_name
773
+	 * @return void
774
+	 * @throws \EE_Error
775
+	 */
776
+	private static function _register_modules($addon_name)
777
+	{
778
+		if (! empty(self::$_settings[$addon_name]['module_paths'])) {
779
+			EE_Register_Module::register(
780
+				$addon_name,
781
+				array('module_paths' => self::$_settings[$addon_name]['module_paths'])
782
+			);
783
+		}
784
+	}
785 785
 
786 786
 
787
-    /**
788
-     * @param string $addon_name
789
-     * @return void
790
-     * @throws \EE_Error
791
-     */
792
-    private static function _register_shortcodes($addon_name)
793
-    {
794
-        if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
795
-            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
796
-        ) {
797
-            EE_Register_Shortcode::register(
798
-                $addon_name,
799
-                array(
800
-                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
801
-                        ? self::$_settings[$addon_name]['shortcode_paths']
802
-                        : array(),
803
-                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
804
-                        ? self::$_settings[$addon_name]['shortcode_fqcns']
805
-                        : array()
806
-                )
807
-            );
808
-        }
809
-    }
787
+	/**
788
+	 * @param string $addon_name
789
+	 * @return void
790
+	 * @throws \EE_Error
791
+	 */
792
+	private static function _register_shortcodes($addon_name)
793
+	{
794
+		if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
795
+			|| ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
796
+		) {
797
+			EE_Register_Shortcode::register(
798
+				$addon_name,
799
+				array(
800
+					'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
801
+						? self::$_settings[$addon_name]['shortcode_paths']
802
+						: array(),
803
+					'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
804
+						? self::$_settings[$addon_name]['shortcode_fqcns']
805
+						: array()
806
+				)
807
+			);
808
+		}
809
+	}
810 810
 
811 811
 
812
-    /**
813
-     * @param string $addon_name
814
-     * @return void
815
-     * @throws \EE_Error
816
-     */
817
-    private static function _register_widgets($addon_name)
818
-    {
819
-        if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
820
-            EE_Register_Widget::register(
821
-                $addon_name,
822
-                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
823
-            );
824
-        }
825
-    }
812
+	/**
813
+	 * @param string $addon_name
814
+	 * @return void
815
+	 * @throws \EE_Error
816
+	 */
817
+	private static function _register_widgets($addon_name)
818
+	{
819
+		if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
820
+			EE_Register_Widget::register(
821
+				$addon_name,
822
+				array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
823
+			);
824
+		}
825
+	}
826 826
 
827 827
 
828
-    /**
829
-     * @param string $addon_name
830
-     * @return void
831
-     * @throws \EE_Error
832
-     */
833
-    private static function _register_capabilities($addon_name)
834
-    {
835
-        if (! empty(self::$_settings[$addon_name]['capabilities'])) {
836
-            EE_Register_Capabilities::register(
837
-                $addon_name,
838
-                array(
839
-                    'capabilities'       => self::$_settings[$addon_name]['capabilities'],
840
-                    'capability_maps'    => self::$_settings[$addon_name]['capability_maps'],
841
-                )
842
-            );
843
-        }
844
-    }
828
+	/**
829
+	 * @param string $addon_name
830
+	 * @return void
831
+	 * @throws \EE_Error
832
+	 */
833
+	private static function _register_capabilities($addon_name)
834
+	{
835
+		if (! empty(self::$_settings[$addon_name]['capabilities'])) {
836
+			EE_Register_Capabilities::register(
837
+				$addon_name,
838
+				array(
839
+					'capabilities'       => self::$_settings[$addon_name]['capabilities'],
840
+					'capability_maps'    => self::$_settings[$addon_name]['capability_maps'],
841
+				)
842
+			);
843
+		}
844
+	}
845 845
 
846 846
 
847
-    /**
848
-     * @param string $addon_name
849
-     * @return void
850
-     * @throws \EE_Error
851
-     */
852
-    private static function _register_message_types($addon_name)
853
-    {
854
-        if (! empty(self::$_settings[$addon_name]['message_types'])) {
855
-            add_action(
856
-                'EE_Brewing_Regular___messages_caf',
857
-                array('EE_Register_Addon', 'register_message_types')
858
-            );
859
-        }
860
-    }
847
+	/**
848
+	 * @param string $addon_name
849
+	 * @return void
850
+	 * @throws \EE_Error
851
+	 */
852
+	private static function _register_message_types($addon_name)
853
+	{
854
+		if (! empty(self::$_settings[$addon_name]['message_types'])) {
855
+			add_action(
856
+				'EE_Brewing_Regular___messages_caf',
857
+				array('EE_Register_Addon', 'register_message_types')
858
+			);
859
+		}
860
+	}
861 861
 
862 862
 
863
-    /**
864
-     * @param string $addon_name
865
-     * @return void
866
-     * @throws \EE_Error
867
-     */
868
-    private static function _register_custom_post_types($addon_name)
869
-    {
870
-        if (
871
-            ! empty(self::$_settings[$addon_name]['custom_post_types'])
872
-            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
873
-        ) {
874
-            EE_Register_CPT::register(
875
-                $addon_name,
876
-                array(
877
-                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
878
-                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
879
-                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
880
-                )
881
-            );
882
-        }
883
-    }
863
+	/**
864
+	 * @param string $addon_name
865
+	 * @return void
866
+	 * @throws \EE_Error
867
+	 */
868
+	private static function _register_custom_post_types($addon_name)
869
+	{
870
+		if (
871
+			! empty(self::$_settings[$addon_name]['custom_post_types'])
872
+			|| ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
873
+		) {
874
+			EE_Register_CPT::register(
875
+				$addon_name,
876
+				array(
877
+					'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
878
+					'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
879
+					'default_terms' => self::$_settings[$addon_name]['default_terms'],
880
+				)
881
+			);
882
+		}
883
+	}
884 884
 
885 885
 
886
-    /**
887
-     * @param string $addon_name
888
-     * @return void
889
-     * @throws \EE_Error
890
-     */
891
-    private static function _register_payment_methods($addon_name)
892
-    {
893
-        if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
894
-            EE_Register_Payment_Method::register(
895
-                $addon_name,
896
-                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
897
-            );
898
-        }
899
-    }
886
+	/**
887
+	 * @param string $addon_name
888
+	 * @return void
889
+	 * @throws \EE_Error
890
+	 */
891
+	private static function _register_payment_methods($addon_name)
892
+	{
893
+		if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
894
+			EE_Register_Payment_Method::register(
895
+				$addon_name,
896
+				array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
897
+			);
898
+		}
899
+	}
900 900
 
901 901
 
902
-    /**
903
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
904
-     *
905
-     * @param string $addon_name
906
-     * @return EE_Addon
907
-     */
908
-    private static function _load_and_init_addon_class($addon_name)
909
-    {
910
-        $addon = EE_Registry::instance()->load_addon(
911
-            dirname(self::$_settings[$addon_name]['main_file_path']),
912
-            self::$_settings[$addon_name]['class_name']
913
-        );
914
-        $addon->set_name($addon_name);
915
-        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
916
-        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
917
-        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
918
-        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
919
-        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
920
-        $addon->set_version(self::$_settings[$addon_name]['version']);
921
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
922
-        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
923
-        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
924
-        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
925
-        //unfortunately this can't be hooked in upon construction, because we don't have
926
-        //the plugin mainfile's path upon construction.
927
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
928
-        // call any additional admin_callback functions during load_admin_controller hook
929
-        if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
930
-            add_action(
931
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
932
-                array($addon, self::$_settings[$addon_name]['admin_callback'])
933
-            );
934
-        }
935
-        return $addon;
936
-    }
902
+	/**
903
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
904
+	 *
905
+	 * @param string $addon_name
906
+	 * @return EE_Addon
907
+	 */
908
+	private static function _load_and_init_addon_class($addon_name)
909
+	{
910
+		$addon = EE_Registry::instance()->load_addon(
911
+			dirname(self::$_settings[$addon_name]['main_file_path']),
912
+			self::$_settings[$addon_name]['class_name']
913
+		);
914
+		$addon->set_name($addon_name);
915
+		$addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
916
+		$addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
917
+		$addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
918
+		$addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
919
+		$addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
920
+		$addon->set_version(self::$_settings[$addon_name]['version']);
921
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
922
+		$addon->set_config_section(self::$_settings[$addon_name]['config_section']);
923
+		$addon->set_config_class(self::$_settings[$addon_name]['config_class']);
924
+		$addon->set_config_name(self::$_settings[$addon_name]['config_name']);
925
+		//unfortunately this can't be hooked in upon construction, because we don't have
926
+		//the plugin mainfile's path upon construction.
927
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
928
+		// call any additional admin_callback functions during load_admin_controller hook
929
+		if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
930
+			add_action(
931
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
932
+				array($addon, self::$_settings[$addon_name]['admin_callback'])
933
+			);
934
+		}
935
+		return $addon;
936
+	}
937 937
 
938 938
 
939
-    /**
940
-     *    load_pue_update - Update notifications
941
-     *
942
-     * @return    void
943
-     */
944
-    public static function load_pue_update()
945
-    {
946
-        // load PUE client
947
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
948
-        // cycle thru settings
949
-        foreach (self::$_settings as $settings) {
950
-            if (! empty($settings['pue_options'])) {
951
-                // initiate the class and start the plugin update engine!
952
-                new PluginUpdateEngineChecker(
953
-                // host file URL
954
-                    'https://eventespresso.com',
955
-                    // plugin slug(s)
956
-                    array(
957
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
958
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
959
-                    ),
960
-                    // options
961
-                    array(
962
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
963
-                        'lang_domain'       => 'event_espresso',
964
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
965
-                        'option_key'        => 'site_license_key',
966
-                        'options_page_slug' => 'event_espresso',
967
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
968
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
969
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
970
-                    )
971
-                );
972
-            }
973
-        }
974
-    }
939
+	/**
940
+	 *    load_pue_update - Update notifications
941
+	 *
942
+	 * @return    void
943
+	 */
944
+	public static function load_pue_update()
945
+	{
946
+		// load PUE client
947
+		require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
948
+		// cycle thru settings
949
+		foreach (self::$_settings as $settings) {
950
+			if (! empty($settings['pue_options'])) {
951
+				// initiate the class and start the plugin update engine!
952
+				new PluginUpdateEngineChecker(
953
+				// host file URL
954
+					'https://eventespresso.com',
955
+					// plugin slug(s)
956
+					array(
957
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
958
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
959
+					),
960
+					// options
961
+					array(
962
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
963
+						'lang_domain'       => 'event_espresso',
964
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
965
+						'option_key'        => 'site_license_key',
966
+						'options_page_slug' => 'event_espresso',
967
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
968
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
969
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
970
+					)
971
+				);
972
+			}
973
+		}
974
+	}
975 975
 
976 976
 
977
-    /**
978
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
979
-     *
980
-     * @since 4.4.0
981
-     * @return void
982
-     * @throws \EE_Error
983
-     */
984
-    public static function register_message_types()
985
-    {
986
-        foreach (self::$_settings as $addon_name => $settings) {
987
-            if (! empty($settings['message_types'])) {
988
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
989
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
990
-                }
991
-            }
992
-        }
993
-    }
977
+	/**
978
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
979
+	 *
980
+	 * @since 4.4.0
981
+	 * @return void
982
+	 * @throws \EE_Error
983
+	 */
984
+	public static function register_message_types()
985
+	{
986
+		foreach (self::$_settings as $addon_name => $settings) {
987
+			if (! empty($settings['message_types'])) {
988
+				foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
989
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
990
+				}
991
+			}
992
+		}
993
+	}
994 994
 
995 995
 
996
-    /**
997
-     * This deregisters an addon that was previously registered with a specific addon_name.
998
-     *
999
-     * @since    4.3.0
1000
-     * @param string $addon_name the name for the addon that was previously registered
1001
-     * @throws EE_Error
1002
-     * @return void
1003
-     */
1004
-    public static function deregister($addon_name = null)
1005
-    {
1006
-        if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
1007
-            do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1008
-            $class_name = self::$_settings[$addon_name]['class_name'];
1009
-            if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
1010
-                // setup DMS
1011
-                EE_Register_Data_Migration_Scripts::deregister($addon_name);
1012
-            }
1013
-            if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1014
-                // register admin page
1015
-                EE_Register_Admin_Page::deregister($addon_name);
1016
-            }
1017
-            if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1018
-                // add to list of modules to be registered
1019
-                EE_Register_Module::deregister($addon_name);
1020
-            }
1021
-            if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
1022
-                || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1023
-            ) {
1024
-                // add to list of shortcodes to be registered
1025
-                EE_Register_Shortcode::deregister($addon_name);
1026
-            }
1027
-            if (! empty(self::$_settings[$addon_name]['config_class'])) {
1028
-                // if config_class present let's register config.
1029
-                EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1030
-            }
1031
-            if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1032
-                // add to list of widgets to be registered
1033
-                EE_Register_Widget::deregister($addon_name);
1034
-            }
1035
-            if (! empty(self::$_settings[$addon_name]['model_paths'])
1036
-                ||
1037
-                ! empty(self::$_settings[$addon_name]['class_paths'])
1038
-            ) {
1039
-                // add to list of shortcodes to be registered
1040
-                EE_Register_Model::deregister($addon_name);
1041
-            }
1042
-            if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1043
-                ||
1044
-                ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1045
-            ) {
1046
-                // add to list of shortcodes to be registered
1047
-                EE_Register_Model_Extensions::deregister($addon_name);
1048
-            }
1049
-            if (! empty(self::$_settings[$addon_name]['message_types'])) {
1050
-                foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1051
-                    EE_Register_Message_Type::deregister($message_type);
1052
-                }
1053
-            }
1054
-            //deregister capabilities for addon
1055
-            if (
1056
-                ! empty(self::$_settings[$addon_name]['capabilities'])
1057
-                || ! empty(self::$_settings[$addon_name]['capability_maps'])
1058
-            ) {
1059
-                EE_Register_Capabilities::deregister($addon_name);
1060
-            }
1061
-            //deregister custom_post_types for addon
1062
-            if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1063
-                EE_Register_CPT::deregister($addon_name);
1064
-            }
1065
-            if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1066
-                EE_Register_Payment_Method::deregister($addon_name);
1067
-            }
1068
-            remove_action(
1069
-                'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1070
-                array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1071
-            );
1072
-            remove_action(
1073
-                'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1074
-                array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1075
-            );
1076
-            unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1077
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1078
-        }
1079
-    }
996
+	/**
997
+	 * This deregisters an addon that was previously registered with a specific addon_name.
998
+	 *
999
+	 * @since    4.3.0
1000
+	 * @param string $addon_name the name for the addon that was previously registered
1001
+	 * @throws EE_Error
1002
+	 * @return void
1003
+	 */
1004
+	public static function deregister($addon_name = null)
1005
+	{
1006
+		if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
1007
+			do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1008
+			$class_name = self::$_settings[$addon_name]['class_name'];
1009
+			if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
1010
+				// setup DMS
1011
+				EE_Register_Data_Migration_Scripts::deregister($addon_name);
1012
+			}
1013
+			if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1014
+				// register admin page
1015
+				EE_Register_Admin_Page::deregister($addon_name);
1016
+			}
1017
+			if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1018
+				// add to list of modules to be registered
1019
+				EE_Register_Module::deregister($addon_name);
1020
+			}
1021
+			if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
1022
+				|| ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1023
+			) {
1024
+				// add to list of shortcodes to be registered
1025
+				EE_Register_Shortcode::deregister($addon_name);
1026
+			}
1027
+			if (! empty(self::$_settings[$addon_name]['config_class'])) {
1028
+				// if config_class present let's register config.
1029
+				EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1030
+			}
1031
+			if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1032
+				// add to list of widgets to be registered
1033
+				EE_Register_Widget::deregister($addon_name);
1034
+			}
1035
+			if (! empty(self::$_settings[$addon_name]['model_paths'])
1036
+				||
1037
+				! empty(self::$_settings[$addon_name]['class_paths'])
1038
+			) {
1039
+				// add to list of shortcodes to be registered
1040
+				EE_Register_Model::deregister($addon_name);
1041
+			}
1042
+			if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1043
+				||
1044
+				! empty(self::$_settings[$addon_name]['class_extension_paths'])
1045
+			) {
1046
+				// add to list of shortcodes to be registered
1047
+				EE_Register_Model_Extensions::deregister($addon_name);
1048
+			}
1049
+			if (! empty(self::$_settings[$addon_name]['message_types'])) {
1050
+				foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1051
+					EE_Register_Message_Type::deregister($message_type);
1052
+				}
1053
+			}
1054
+			//deregister capabilities for addon
1055
+			if (
1056
+				! empty(self::$_settings[$addon_name]['capabilities'])
1057
+				|| ! empty(self::$_settings[$addon_name]['capability_maps'])
1058
+			) {
1059
+				EE_Register_Capabilities::deregister($addon_name);
1060
+			}
1061
+			//deregister custom_post_types for addon
1062
+			if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1063
+				EE_Register_CPT::deregister($addon_name);
1064
+			}
1065
+			if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1066
+				EE_Register_Payment_Method::deregister($addon_name);
1067
+			}
1068
+			remove_action(
1069
+				'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1070
+				array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1071
+			);
1072
+			remove_action(
1073
+				'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1074
+				array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1075
+			);
1076
+			unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1077
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1078
+		}
1079
+	}
1080 1080
 
1081 1081
 
1082 1082
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
         // offsets:    0 . 1 . 2 . 3 . 4
67 67
         $version_parts = explode('.', $min_core_version);
68 68
         //check they specified the micro version (after 2nd period)
69
-        if (! isset($version_parts[2])) {
69
+        if ( ! isset($version_parts[2])) {
70 70
             $version_parts[2] = '0';
71 71
         }
72 72
         //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73 73
         //soon we can assume that's 'rc', but this current version is 'alpha'
74
-        if (! isset($version_parts[3])) {
74
+        if ( ! isset($version_parts[3])) {
75 75
             $version_parts[3] = 'dev';
76 76
         }
77
-        if (! isset($version_parts[4])) {
77
+        if ( ! isset($version_parts[4])) {
78 78
             $version_parts[4] = '000';
79 79
         }
80 80
         return implode('.', $version_parts);
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         // setup PUE
232 232
         \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233 233
         // does this addon work with this version of core or WordPress ?
234
-        if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
234
+        if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235 235
             return;
236 236
         }
237 237
         // register namespaces
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 )
289 289
             );
290 290
         }
291
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
291
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292 292
             throw new EE_Error(
293 293
                 sprintf(
294 294
                     __(
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         } else {
330 330
             $class_name = $setup_args['class_name'];
331 331
         }
332
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
332
+        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name;
333 333
     }
334 334
 
335 335
 
@@ -346,108 +346,108 @@  discard block
 block discarded – undo
346 346
             'class_name'            => $class_name,
347 347
             // the addon slug for use in URLs, etc
348 348
             'plugin_slug'           => isset($setup_args['plugin_slug'])
349
-                ? (string)$setup_args['plugin_slug']
349
+                ? (string) $setup_args['plugin_slug']
350 350
                 : '',
351 351
             // page slug to be used when generating the "Settings" link on the WP plugin page
352 352
             'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
-                ? (string)$setup_args['plugin_action_slug']
353
+                ? (string) $setup_args['plugin_action_slug']
354 354
                 : '',
355 355
             // the "software" version for the addon
356 356
             'version'               => isset($setup_args['version'])
357
-                ? (string)$setup_args['version']
357
+                ? (string) $setup_args['version']
358 358
                 : '',
359 359
             // the minimum version of EE Core that the addon will work with
360 360
             'min_core_version'      => isset($setup_args['min_core_version'])
361
-                ? (string)$setup_args['min_core_version']
361
+                ? (string) $setup_args['min_core_version']
362 362
                 : '',
363 363
             // the minimum version of WordPress that the addon will work with
364 364
             'min_wp_version'        => isset($setup_args['min_wp_version'])
365
-                ? (string)$setup_args['min_wp_version']
365
+                ? (string) $setup_args['min_wp_version']
366 366
                 : EE_MIN_WP_VER_REQUIRED,
367 367
             // full server path to main file (file loaded directly by WP)
368 368
             'main_file_path'        => isset($setup_args['main_file_path'])
369
-                ? (string)$setup_args['main_file_path']
369
+                ? (string) $setup_args['main_file_path']
370 370
                 : '',
371 371
             // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372 372
             'admin_path'            => isset($setup_args['admin_path'])
373
-                ? (string)$setup_args['admin_path'] : '',
373
+                ? (string) $setup_args['admin_path'] : '',
374 374
             // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375 375
             'admin_callback'        => isset($setup_args['admin_callback'])
376
-                ? (string)$setup_args['admin_callback']
376
+                ? (string) $setup_args['admin_callback']
377 377
                 : '',
378 378
             // the section name for this addon's configuration settings section (defaults to "addons")
379 379
             'config_section'        => isset($setup_args['config_section'])
380
-                ? (string)$setup_args['config_section']
380
+                ? (string) $setup_args['config_section']
381 381
                 : 'addons',
382 382
             // the class name for this addon's configuration settings object
383 383
             'config_class'          => isset($setup_args['config_class'])
384
-                ? (string)$setup_args['config_class'] : '',
384
+                ? (string) $setup_args['config_class'] : '',
385 385
             //the name given to the config for this addons' configuration settings object (optional)
386 386
             'config_name'           => isset($setup_args['config_name'])
387
-                ? (string)$setup_args['config_name'] : '',
387
+                ? (string) $setup_args['config_name'] : '',
388 388
             // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389 389
             'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
-                ? (array)$setup_args['autoloader_paths']
390
+                ? (array) $setup_args['autoloader_paths']
391 391
                 : array(),
392 392
             // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393 393
             'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
-                ? (array)$setup_args['autoloader_folders']
394
+                ? (array) $setup_args['autoloader_folders']
395 395
                 : array(),
396 396
             // array of full server paths to any EE_DMS data migration scripts used by the addon
397 397
             'dms_paths'             => isset($setup_args['dms_paths'])
398
-                ? (array)$setup_args['dms_paths']
398
+                ? (array) $setup_args['dms_paths']
399 399
                 : array(),
400 400
             // array of full server paths to any EED_Modules used by the addon
401 401
             'module_paths'          => isset($setup_args['module_paths'])
402
-                ? (array)$setup_args['module_paths']
402
+                ? (array) $setup_args['module_paths']
403 403
                 : array(),
404 404
             // array of full server paths to any EES_Shortcodes used by the addon
405 405
             'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
-                ? (array)$setup_args['shortcode_paths']
406
+                ? (array) $setup_args['shortcode_paths']
407 407
                 : array(),
408 408
             'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
409 409
                 ? (array) $setup_args['shortcode_fqcns']
410 410
                 : array(),
411 411
             // array of full server paths to any WP_Widgets used by the addon
412 412
             'widget_paths'          => isset($setup_args['widget_paths'])
413
-                ? (array)$setup_args['widget_paths']
413
+                ? (array) $setup_args['widget_paths']
414 414
                 : array(),
415 415
             // array of PUE options used by the addon
416 416
             'pue_options'           => isset($setup_args['pue_options'])
417
-                ? (array)$setup_args['pue_options']
417
+                ? (array) $setup_args['pue_options']
418 418
                 : array(),
419 419
             'message_types'         => isset($setup_args['message_types'])
420
-                ? (array)$setup_args['message_types']
420
+                ? (array) $setup_args['message_types']
421 421
                 : array(),
422 422
             'capabilities'          => isset($setup_args['capabilities'])
423
-                ? (array)$setup_args['capabilities']
423
+                ? (array) $setup_args['capabilities']
424 424
                 : array(),
425 425
             'capability_maps'       => isset($setup_args['capability_maps'])
426
-                ? (array)$setup_args['capability_maps']
426
+                ? (array) $setup_args['capability_maps']
427 427
                 : array(),
428 428
             'model_paths'           => isset($setup_args['model_paths'])
429
-                ? (array)$setup_args['model_paths']
429
+                ? (array) $setup_args['model_paths']
430 430
                 : array(),
431 431
             'class_paths'           => isset($setup_args['class_paths'])
432
-                ? (array)$setup_args['class_paths']
432
+                ? (array) $setup_args['class_paths']
433 433
                 : array(),
434 434
             'model_extension_paths' => isset($setup_args['model_extension_paths'])
435
-                ? (array)$setup_args['model_extension_paths']
435
+                ? (array) $setup_args['model_extension_paths']
436 436
                 : array(),
437 437
             'class_extension_paths' => isset($setup_args['class_extension_paths'])
438
-                ? (array)$setup_args['class_extension_paths']
438
+                ? (array) $setup_args['class_extension_paths']
439 439
                 : array(),
440 440
             'custom_post_types'     => isset($setup_args['custom_post_types'])
441
-                ? (array)$setup_args['custom_post_types']
441
+                ? (array) $setup_args['custom_post_types']
442 442
                 : array(),
443 443
             'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
444
-                ? (array)$setup_args['custom_taxonomies']
444
+                ? (array) $setup_args['custom_taxonomies']
445 445
                 : array(),
446 446
             'payment_method_paths'  => isset($setup_args['payment_method_paths'])
447
-                ? (array)$setup_args['payment_method_paths']
447
+                ? (array) $setup_args['payment_method_paths']
448 448
                 : array(),
449 449
             'default_terms'         => isset($setup_args['default_terms'])
450
-                ? (array)$setup_args['default_terms']
450
+                ? (array) $setup_args['default_terms']
451 451
                 : array(),
452 452
             // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
453 453
             // that can be used for adding upgrading/marketing info
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
                 $setup_args['namespace']['FQNS'],
460 460
                 $setup_args['namespace']['DIR']
461 461
             )
462
-                ? (array)$setup_args['namespace']
462
+                ? (array) $setup_args['namespace']
463 463
                 : array(),
464 464
         );
465 465
         // if plugin_action_slug is NOT set, but an admin page path IS set,
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
                 '</span><br />'
530 530
             );
531 531
         }
532
-        if (! empty($incompatibility_message)) {
532
+        if ( ! empty($incompatibility_message)) {
533 533
             // remove 'activate' from the REQUEST
534 534
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
535 535
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -557,19 +557,19 @@  discard block
 block discarded – undo
557 557
      */
558 558
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
559 559
     {
560
-        if (! empty($setup_args['pue_options'])) {
560
+        if ( ! empty($setup_args['pue_options'])) {
561 561
             self::$_settings[$addon_name]['pue_options'] = array(
562 562
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
563
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
564
-                    : 'espresso_' . strtolower($class_name),
563
+                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
564
+                    : 'espresso_'.strtolower($class_name),
565 565
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
566
-                    ? (string)$setup_args['pue_options']['plugin_basename']
566
+                    ? (string) $setup_args['pue_options']['plugin_basename']
567 567
                     : plugin_basename($setup_args['main_file_path']),
568 568
                 'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
569
-                    ? (string)$setup_args['pue_options']['checkPeriod']
569
+                    ? (string) $setup_args['pue_options']['checkPeriod']
570 570
                     : '24',
571 571
                 'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
572
-                    ? (string)$setup_args['pue_options']['use_wp_update']
572
+                    ? (string) $setup_args['pue_options']['use_wp_update']
573 573
                     : false,
574 574
             );
575 575
             add_action(
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
             //(as the newly-activated addon wasn't around the first time addons were registered).
618 618
             //Note: the presence of pue_options in the addon registration options will initialize the $_settings
619 619
             //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
620
-            if (! isset(self::$_settings[$addon_name])
620
+            if ( ! isset(self::$_settings[$addon_name])
621 621
                 || (isset(self::$_settings[$addon_name])
622 622
                     && ! isset(self::$_settings[$addon_name]['class_name'])
623 623
                 )
@@ -664,13 +664,13 @@  discard block
 block discarded – undo
664 664
      */
665 665
     private static function _setup_autoloaders($addon_name)
666 666
     {
667
-        if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
667
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
668 668
             // setup autoloader for single file
669 669
             EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
670 670
         }
671 671
         // setup autoloaders for folders
672
-        if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
672
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
674 674
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
675 675
             }
676 676
         }
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
     private static function _register_data_migration_scripts($addon_name)
724 724
     {
725 725
         // setup DMS
726
-        if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
726
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
727 727
             EE_Register_Data_Migration_Scripts::register(
728 728
                 $addon_name,
729 729
                 array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
     private static function _register_config($addon_name)
741 741
     {
742 742
         // if config_class is present let's register config.
743
-        if (! empty(self::$_settings[$addon_name]['config_class'])) {
743
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
744 744
             EE_Register_Config::register(
745 745
                 self::$_settings[$addon_name]['config_class'],
746 746
                 array(
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
      */
760 760
     private static function _register_admin_pages($addon_name)
761 761
     {
762
-        if (! empty(self::$_settings[$addon_name]['admin_path'])) {
762
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
763 763
             EE_Register_Admin_Page::register(
764 764
                 $addon_name,
765 765
                 array('page_path' => self::$_settings[$addon_name]['admin_path'])
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      */
776 776
     private static function _register_modules($addon_name)
777 777
     {
778
-        if (! empty(self::$_settings[$addon_name]['module_paths'])) {
778
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
779 779
             EE_Register_Module::register(
780 780
                 $addon_name,
781 781
                 array('module_paths' => self::$_settings[$addon_name]['module_paths'])
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
      */
792 792
     private static function _register_shortcodes($addon_name)
793 793
     {
794
-        if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
794
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
795 795
             || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
796 796
         ) {
797 797
             EE_Register_Shortcode::register(
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
      */
817 817
     private static function _register_widgets($addon_name)
818 818
     {
819
-        if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
819
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
820 820
             EE_Register_Widget::register(
821 821
                 $addon_name,
822 822
                 array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
      */
833 833
     private static function _register_capabilities($addon_name)
834 834
     {
835
-        if (! empty(self::$_settings[$addon_name]['capabilities'])) {
835
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
836 836
             EE_Register_Capabilities::register(
837 837
                 $addon_name,
838 838
                 array(
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
      */
852 852
     private static function _register_message_types($addon_name)
853 853
     {
854
-        if (! empty(self::$_settings[$addon_name]['message_types'])) {
854
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
855 855
             add_action(
856 856
                 'EE_Brewing_Regular___messages_caf',
857 857
                 array('EE_Register_Addon', 'register_message_types')
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
      */
891 891
     private static function _register_payment_methods($addon_name)
892 892
     {
893
-        if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
893
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
894 894
             EE_Register_Payment_Method::register(
895 895
                 $addon_name,
896 896
                 array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
         //the plugin mainfile's path upon construction.
927 927
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
928 928
         // call any additional admin_callback functions during load_admin_controller hook
929
-        if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
929
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
930 930
             add_action(
931 931
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
932 932
                 array($addon, self::$_settings[$addon_name]['admin_callback'])
@@ -944,10 +944,10 @@  discard block
 block discarded – undo
944 944
     public static function load_pue_update()
945 945
     {
946 946
         // load PUE client
947
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
947
+        require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php';
948 948
         // cycle thru settings
949 949
         foreach (self::$_settings as $settings) {
950
-            if (! empty($settings['pue_options'])) {
950
+            if ( ! empty($settings['pue_options'])) {
951 951
                 // initiate the class and start the plugin update engine!
952 952
                 new PluginUpdateEngineChecker(
953 953
                 // host file URL
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
                     // plugin slug(s)
956 956
                     array(
957 957
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
958
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
958
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
959 959
                     ),
960 960
                     // options
961 961
                     array(
@@ -984,8 +984,8 @@  discard block
 block discarded – undo
984 984
     public static function register_message_types()
985 985
     {
986 986
         foreach (self::$_settings as $addon_name => $settings) {
987
-            if (! empty($settings['message_types'])) {
988
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
987
+            if ( ! empty($settings['message_types'])) {
988
+                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
989 989
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
990 990
                 }
991 991
             }
@@ -1006,48 +1006,48 @@  discard block
 block discarded – undo
1006 1006
         if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
1007 1007
             do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1008 1008
             $class_name = self::$_settings[$addon_name]['class_name'];
1009
-            if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
1009
+            if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1010 1010
                 // setup DMS
1011 1011
                 EE_Register_Data_Migration_Scripts::deregister($addon_name);
1012 1012
             }
1013
-            if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1013
+            if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1014 1014
                 // register admin page
1015 1015
                 EE_Register_Admin_Page::deregister($addon_name);
1016 1016
             }
1017
-            if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1017
+            if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1018 1018
                 // add to list of modules to be registered
1019 1019
                 EE_Register_Module::deregister($addon_name);
1020 1020
             }
1021
-            if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
1021
+            if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1022 1022
                 || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1023 1023
             ) {
1024 1024
                 // add to list of shortcodes to be registered
1025 1025
                 EE_Register_Shortcode::deregister($addon_name);
1026 1026
             }
1027
-            if (! empty(self::$_settings[$addon_name]['config_class'])) {
1027
+            if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1028 1028
                 // if config_class present let's register config.
1029 1029
                 EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1030 1030
             }
1031
-            if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1031
+            if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1032 1032
                 // add to list of widgets to be registered
1033 1033
                 EE_Register_Widget::deregister($addon_name);
1034 1034
             }
1035
-            if (! empty(self::$_settings[$addon_name]['model_paths'])
1035
+            if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1036 1036
                 ||
1037 1037
                 ! empty(self::$_settings[$addon_name]['class_paths'])
1038 1038
             ) {
1039 1039
                 // add to list of shortcodes to be registered
1040 1040
                 EE_Register_Model::deregister($addon_name);
1041 1041
             }
1042
-            if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1042
+            if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1043 1043
                 ||
1044 1044
                 ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1045 1045
             ) {
1046 1046
                 // add to list of shortcodes to be registered
1047 1047
                 EE_Register_Model_Extensions::deregister($addon_name);
1048 1048
             }
1049
-            if (! empty(self::$_settings[$addon_name]['message_types'])) {
1050
-                foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1049
+            if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1050
+                foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1051 1051
                     EE_Register_Message_Type::deregister($message_type);
1052 1052
                 }
1053 1053
             }
@@ -1059,14 +1059,14 @@  discard block
 block discarded – undo
1059 1059
                 EE_Register_Capabilities::deregister($addon_name);
1060 1060
             }
1061 1061
             //deregister custom_post_types for addon
1062
-            if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1062
+            if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1063 1063
                 EE_Register_CPT::deregister($addon_name);
1064 1064
             }
1065
-            if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1065
+            if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1066 1066
                 EE_Register_Payment_Method::deregister($addon_name);
1067 1067
             }
1068 1068
             remove_action(
1069
-                'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1069
+                'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1070 1070
                 array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1071 1071
             );
1072 1072
             remove_action(
Please login to merge, or discard this patch.