Completed
Branch BUG-10489-non-trashed-regs-onl... (a7561f)
by
unknown
46:07 queued 34:09
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   +10 added lines, -10 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
 
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
                 'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
159 159
                     esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
160 160
                 'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
161
-                    esc_html__('Event Phone Number', 'event_espresso'), false,''),
161
+                    esc_html__('Event Phone Number', 'event_espresso'), false, ''),
162 162
                 'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
163 163
                     esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
164 164
                 'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
165
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''),
165
+                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false, ''),
166 166
                 'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
167 167
                     esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
168 168
                 'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
@@ -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 integer $default_value
374
-     * @return EE_Integer_Field
375
-     */
376
-    public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0)
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 integer $default_value
374
+	 * @return EE_Integer_Field
375
+	 */
376
+	public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0)
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.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
                 && $most_recent_migration->is_broken()
262 262
             )
263 263
         ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
264
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
265 265
             $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266 266
             $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267 267
                                                                                         'success' => '0',
268 268
             ), EE_MAINTENANCE_ADMIN_URL);
269 269
         } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
270
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
271 271
         } else {
272 272
             if ($most_recent_migration
273 273
                 && $most_recent_migration instanceof EE_Data_Migration_Script_Base
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 $this->_template_args['current_db_state'] = null;
298 298
                 $this->_template_args['next_db_state'] = null;
299 299
             }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
300
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
301 301
             $this->_template_args = array_merge(
302 302
                 $this->_template_args,
303 303
                 array(
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
                 'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337 337
             ));
338 338
         }
339
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
339
+        $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
340 340
         //now render the migration options part, and put it in a variable
341 341
         $migration_options_template_file = apply_filters(
342 342
             'FHEE__ee_migration_page__migration_options_template',
343
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
343
+            EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php'
344 344
         );
345
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
345
+        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true);
346 346
         $this->_template_args['migration_options_html'] = $migration_options_html;
347 347
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348 348
             $this->_template_args, true);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
      */
402 402
     public function _data_reset_and_delete()
403 403
     {
404
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
404
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
405 405
         $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406 406
             'reset_reservations',
407 407
             'reset_reservations',
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 
439 439
     protected function _reset_reservations()
440 440
     {
441
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
441
+        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442 442
             EE_Error::add_success(
443 443
                 __(
444 444
                     'Ticket and datetime reserved counts have been successfully reset.',
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
      */
487 487
     public function _system_status()
488 488
     {
489
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
489
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
490 490
         $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491 491
         $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492 492
             array(
@@ -505,11 +505,11 @@  discard block
 block discarded – undo
505 505
     public function _download_system_status()
506 506
     {
507 507
         $status_info = EEM_System_Status::instance()->get_system_stati();
508
-        header( 'Content-Disposition: attachment' );
509
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
508
+        header('Content-Disposition: attachment');
509
+        header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html");
510 510
         echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
511
-        echo "<h1>System Information for " . site_url() . "</h1>";
512
-        echo EEH_Template::layout_array_as_table( $status_info );
511
+        echo "<h1>System Information for ".site_url()."</h1>";
512
+        echo EEH_Template::layout_array_as_table($status_info);
513 513
         die;
514 514
     }
515 515
 
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         try {
524 524
             $success = wp_mail(EE_SUPPORT_EMAIL,
525 525
                 'Migration Crash Report',
526
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
526
+                $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
527 527
                 array(
528 528
                     "from:$from_name<$from>",
529 529
                     //					'content-type:text/html charset=UTF-8'
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
             EE_MAINTENANCE_ADMIN_URL);
559 559
         $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560 560
             EE_MAINTENANCE_ADMIN_URL);
561
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
561
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
562 562
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563 563
             $this->_template_args, true);
564 564
         $this->display_admin_page_with_sidebar();
@@ -659,9 +659,9 @@  discard block
 block discarded – undo
659 659
         wp_enqueue_script('ee_admin_js');
660 660
 //		wp_enqueue_media();
661 661
 //		wp_enqueue_script('media-upload');
662
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
662
+        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'),
663 663
             EVENT_ESPRESSO_VERSION, true);
664
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
664
+        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(),
665 665
             EVENT_ESPRESSO_VERSION);
666 666
         wp_enqueue_style('espresso_maintenance');
667 667
     }
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
 
699 699
     protected function _get_datetime_offset_fix_form()
700 700
     {
701
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
701
+        if ( ! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
+            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
703 703
                 array(
704 704
                     'name' => 'datetime_offset_fix_option',
705 705
                     'layout_strategy' => new EE_Admin_Two_Column_Layout(),
Please login to merge, or discard this patch.
Indentation   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -28,755 +28,755 @@
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * @var EE_Datetime_Offset_Fix_Form
33
-     */
34
-    protected $datetime_fix_offset_form;
35
-
36
-
37
-
38
-    protected function _init_page_props()
39
-    {
40
-        $this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
-        $this->page_label = EE_MAINTENANCE_LABEL;
42
-        $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
-    }
45
-
46
-
47
-
48
-    protected function _ajax_hooks()
49
-    {
50
-        add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
-        add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
-    }
53
-
54
-
55
-
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
-        $this->_labels = array(
60
-            'buttons' => array(
61
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
-            ),
64
-        );
65
-    }
66
-
67
-
68
-
69
-    protected function _set_page_routes()
70
-    {
71
-        $this->_page_routes = array(
72
-            'default'                             => array(
73
-                'func'       => '_maintenance',
74
-                'capability' => 'manage_options',
75
-            ),
76
-            'change_maintenance_level'            => array(
77
-                'func'       => '_change_maintenance_level',
78
-                'capability' => 'manage_options',
79
-                'noheader'   => true,
80
-            ),
81
-            'system_status'                       => array(
82
-                'func'       => '_system_status',
83
-                'capability' => 'manage_options',
84
-            ),
85
-            'download_system_status' => array(
86
-                'func'       => '_download_system_status',
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ),
90
-            'send_migration_crash_report'         => array(
91
-                'func'       => '_send_migration_crash_report',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ),
95
-            'confirm_migration_crash_report_sent' => array(
96
-                'func'       => '_confirm_migration_crash_report_sent',
97
-                'capability' => 'manage_options',
98
-            ),
99
-            'data_reset'                          => array(
100
-                'func'       => '_data_reset_and_delete',
101
-                'capability' => 'manage_options',
102
-            ),
103
-            'reset_db'                            => array(
104
-                'func'       => '_reset_db',
105
-                'capability' => 'manage_options',
106
-                'noheader'   => true,
107
-                'args'       => array('nuke_old_ee4_data' => true),
108
-            ),
109
-            'start_with_fresh_ee4_db'             => array(
110
-                'func'       => '_reset_db',
111
-                'capability' => 'manage_options',
112
-                'noheader'   => true,
113
-                'args'       => array('nuke_old_ee4_data' => false),
114
-            ),
115
-            'delete_db'                           => array(
116
-                'func'       => '_delete_db',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ),
120
-            'rerun_migration_from_ee3'            => array(
121
-                'func'       => '_rerun_migration_from_ee3',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-            'reset_reservations'                  => array(
126
-                'func'       => '_reset_reservations',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-            'reset_capabilities'                  => array(
131
-                'func'       => '_reset_capabilities',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-            'reattempt_migration'                 => array(
136
-                'func'       => '_reattempt_migration',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ),
140
-            'datetime_tools' => array(
141
-                'func' => '_datetime_tools',
142
-                'capability' => 'manage_options'
143
-            ),
144
-            'run_datetime_offset_fix' => array(
145
-                'func' => '_apply_datetime_offset',
146
-                'noheader' => true,
147
-                'headers_sent_route' => 'datetime_tools',
148
-                'capability' => 'manage_options'
149
-            )
150
-        );
151
-    }
152
-
153
-
154
-
155
-    protected function _set_page_config()
156
-    {
157
-        $this->_page_config = array(
158
-            'default'       => array(
159
-                'nav'           => array(
160
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
161
-                    'order' => 10,
162
-                ),
163
-                'require_nonce' => false,
164
-            ),
165
-            'data_reset'    => array(
166
-                'nav'           => array(
167
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
168
-                    'order' => 20,
169
-                ),
170
-                'require_nonce' => false,
171
-            ),
172
-            'datetime_tools' => array(
173
-                'nav' => array(
174
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
175
-                    'order' => 25
176
-                ),
177
-                'require_nonce' => false,
178
-            ),
179
-            'system_status' => array(
180
-                'nav'           => array(
181
-                    'label' => esc_html__("System Information", "event_espresso"),
182
-                    'order' => 30,
183
-                ),
184
-                'require_nonce' => false,
185
-            ),
186
-        );
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * default maintenance page. If we're in maintenance mode level 2, then we need to show
193
-     * the migration scripts and all that UI.
194
-     */
195
-    public function _maintenance()
196
-    {
197
-        //it all depends if we're in maintenance model level 1 (frontend-only) or
198
-        //level 2 (everything except maintenance page)
199
-        try {
200
-            //get the current maintenance level and check if
201
-            //we are removed
202
-            $mm = EE_Maintenance_Mode::instance()->level();
203
-            $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
204
-            if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
205
-                //we just took the site out of maintenance mode, so notify the user.
206
-                //unfortunately this message appears to be echoed on the NEXT page load...
207
-                //oh well, we should really be checking for this on addon deactivation anyways
208
-                EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
209
-                    'event_espresso'));
210
-                $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
211
-            }
212
-            //in case an exception is thrown while trying to handle migrations
213
-            switch (EE_Maintenance_Mode::instance()->level()) {
214
-                case EE_Maintenance_Mode::level_0_not_in_maintenance:
215
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
216
-                    $show_maintenance_switch = true;
217
-                    $show_backup_db_text = false;
218
-                    $show_migration_progress = false;
219
-                    $script_names = array();
220
-                    $addons_should_be_upgraded_first = false;
221
-                    break;
222
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
223
-                    $show_maintenance_switch = false;
224
-                    $show_migration_progress = true;
225
-                    if (isset($this->_req_data['continue_migration'])) {
226
-                        $show_backup_db_text = false;
227
-                    } else {
228
-                        $show_backup_db_text = true;
229
-                    }
230
-                    $scripts_needing_to_run = EE_Data_Migration_Manager::instance()
231
-                                                                       ->check_for_applicable_data_migration_scripts();
232
-                    $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
233
-                    $script_names = array();
234
-                    $current_script = null;
235
-                    foreach ($scripts_needing_to_run as $script) {
236
-                        if ($script instanceof EE_Data_Migration_Script_Base) {
237
-                            if ( ! $current_script) {
238
-                                $current_script = $script;
239
-                                $current_script->migration_page_hooks();
240
-                            }
241
-                            $script_names[] = $script->pretty_name();
242
-                        }
243
-                    }
244
-                    break;
245
-            }
246
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
247
-            $exception_thrown = false;
248
-        } catch (EE_Error $e) {
249
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
250
-            //now, just so we can display the page correctly, make a error migration script stage object
251
-            //and also put the error on it. It only persists for the duration of this request
252
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
253
-            $most_recent_migration->add_error($e->getMessage());
254
-            $exception_thrown = true;
255
-        }
256
-        $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
257
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
258
-        if ($exception_thrown
259
-            || ($most_recent_migration
260
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
261
-                && $most_recent_migration->is_broken()
262
-            )
263
-        ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
265
-            $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266
-            $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267
-                                                                                        'success' => '0',
268
-            ), EE_MAINTENANCE_ADMIN_URL);
269
-        } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
271
-        } else {
272
-            if ($most_recent_migration
273
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
274
-                && $most_recent_migration->can_continue()
275
-            ) {
276
-                $show_backup_db_text = false;
277
-                $show_continue_current_migration_script = true;
278
-                $show_most_recent_migration = true;
279
-            } elseif (isset($this->_req_data['continue_migration'])) {
280
-                $show_most_recent_migration = true;
281
-                $show_continue_current_migration_script = false;
282
-            } else {
283
-                $show_most_recent_migration = false;
284
-                $show_continue_current_migration_script = false;
285
-            }
286
-            if (isset($current_script)) {
287
-                $migrates_to = $current_script->migrates_to_version();
288
-                $plugin_slug = $migrates_to['slug'];
289
-                $new_version = $migrates_to['version'];
290
-                $this->_template_args = array_merge($this->_template_args, array(
291
-                    'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
292
-                        isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
293
-                    'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
294
-                        $new_version, $plugin_slug) : null,
295
-                ));
296
-            } else {
297
-                $this->_template_args['current_db_state'] = null;
298
-                $this->_template_args['next_db_state'] = null;
299
-            }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
-            $this->_template_args = array_merge(
302
-                $this->_template_args,
303
-                array(
304
-                    'show_most_recent_migration'             => $show_most_recent_migration,
305
-                    //flag for showing the most recent migration's status and/or errors
306
-                    'show_migration_progress'                => $show_migration_progress,
307
-                    //flag for showing the option to run migrations and see their progress
308
-                    'show_backup_db_text'                    => $show_backup_db_text,
309
-                    //flag for showing text telling the user to backup their DB
310
-                    'show_maintenance_switch'                => $show_maintenance_switch,
311
-                    //flag for showing the option to change maintenance mode between levels 0 and 1
312
-                    'script_names'                           => $script_names,
313
-                    //array of names of scripts that have run
314
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
-                    //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
317
-                        EE_MAINTENANCE_ADMIN_URL),
318
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
319
-                        EE_MAINTENANCE_ADMIN_URL),
320
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
321
-                        EE_MAINTENANCE_ADMIN_URL),
322
-                    'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
323
-                        espresso_version()),
324
-                )
325
-            );
326
-            //make sure we have the form fields helper available. It usually is, but sometimes it isn't
327
-            //localize script stuff
328
-            wp_localize_script('ee-maintenance', 'ee_maintenance', array(
329
-                'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
330
-                'next'                             => esc_html__("Next", "event_espresso"),
331
-                'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
332
-                'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
333
-                    "event_espresso"),
334
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
335
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
336
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337
-            ));
338
-        }
339
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
340
-        //now render the migration options part, and put it in a variable
341
-        $migration_options_template_file = apply_filters(
342
-            'FHEE__ee_migration_page__migration_options_template',
343
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
344
-        );
345
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
346
-        $this->_template_args['migration_options_html'] = $migration_options_html;
347
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348
-            $this->_template_args, true);
349
-        $this->display_admin_page_with_sidebar();
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
356
-     */
357
-    public function migration_step()
358
-    {
359
-        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
360
-        $this->_return_json();
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * Can be used by js when it notices a response with HTML in it in order
367
-     * to log the malformed response
368
-     */
369
-    public function add_error_to_migrations_ran()
370
-    {
371
-        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
372
-        $this->_template_args['data'] = array('ok' => true);
373
-        $this->_return_json();
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * changes the maintenance level, provided there are still no migration scripts that should run
380
-     */
381
-    public function _change_maintenance_level()
382
-    {
383
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
384
-        if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
385
-            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
386
-            $success = true;
387
-        } else {
388
-            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
389
-            $success = false;
390
-        }
391
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * a tab with options for resetting and/or deleting EE data
398
-     *
399
-     * @throws \EE_Error
400
-     * @throws \DomainException
401
-     */
402
-    public function _data_reset_and_delete()
403
-    {
404
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
405
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406
-            'reset_reservations',
407
-            'reset_reservations',
408
-            array(),
409
-            'button button-primary',
410
-            '',
411
-            false
412
-        );
413
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
414
-            'reset_capabilities',
415
-            'reset_capabilities',
416
-            array(),
417
-            'button button-primary',
418
-            '',
419
-            false
420
-        );
421
-        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
422
-            array('action' => 'delete_db'),
423
-            EE_MAINTENANCE_ADMIN_URL
424
-        );
425
-        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
426
-            array('action' => 'reset_db'),
427
-            EE_MAINTENANCE_ADMIN_URL
428
-        );
429
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
430
-            $this->_template_path,
431
-            $this->_template_args,
432
-            true
433
-        );
434
-        $this->display_admin_page_with_sidebar();
435
-    }
436
-
437
-
438
-
439
-    protected function _reset_reservations()
440
-    {
441
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442
-            EE_Error::add_success(
443
-                __(
444
-                    'Ticket and datetime reserved counts have been successfully reset.',
445
-                    'event_espresso'
446
-                )
447
-            );
448
-        } else {
449
-            EE_Error::add_success(
450
-                __(
451
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
452
-                    'event_espresso'
453
-                )
454
-            );
455
-        }
456
-        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
457
-    }
458
-
459
-
460
-
461
-    protected function _reset_capabilities()
462
-    {
463
-        EE_Registry::instance()->CAP->init_caps(true);
464
-        EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
465
-            'event_espresso'));
466
-        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     * resets the DMSs so we can attempt to continue migrating after a fatal error
473
-     * (only a good idea when someone has somehow tried ot fix whatever caused
474
-     * the fatal error in teh first place)
475
-     */
476
-    protected function _reattempt_migration()
477
-    {
478
-        EE_Data_Migration_Manager::instance()->reattempt();
479
-        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * shows the big ol' System Information page
486
-     */
487
-    public function _system_status()
488
-    {
489
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
490
-        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492
-            array(
493
-                'action' => 'download_system_status',
494
-            ),
495
-            EE_MAINTENANCE_ADMIN_URL
496
-        );
497
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
498
-            $this->_template_args, true);
499
-        $this->display_admin_page_with_sidebar();
500
-    }
501
-
502
-    /**
503
-     * Downloads an HTML file of the system status that can be easily stored or emailed
504
-     */
505
-    public function _download_system_status()
506
-    {
507
-        $status_info = EEM_System_Status::instance()->get_system_stati();
508
-        header( 'Content-Disposition: attachment' );
509
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
510
-        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
511
-        echo "<h1>System Information for " . site_url() . "</h1>";
512
-        echo EEH_Template::layout_array_as_table( $status_info );
513
-        die;
514
-    }
515
-
516
-
517
-
518
-    public function _send_migration_crash_report()
519
-    {
520
-        $from = $this->_req_data['from'];
521
-        $from_name = $this->_req_data['from_name'];
522
-        $body = $this->_req_data['body'];
523
-        try {
524
-            $success = wp_mail(EE_SUPPORT_EMAIL,
525
-                'Migration Crash Report',
526
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
527
-                array(
528
-                    "from:$from_name<$from>",
529
-                    //					'content-type:text/html charset=UTF-8'
530
-                ));
531
-        } catch (Exception $e) {
532
-            $success = false;
533
-        }
534
-        $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
535
-            esc_html__("sent", "event_espresso"),
536
-            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
537
-    }
538
-
539
-
540
-
541
-    public function _confirm_migration_crash_report_sent()
542
-    {
543
-        try {
544
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
545
-        } catch (EE_Error $e) {
546
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
547
-            //now, just so we can display the page correctly, make a error migration script stage object
548
-            //and also put the error on it. It only persists for the duration of this request
549
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
550
-            $most_recent_migration->add_error($e->getMessage());
551
-        }
552
-        $success = $this->_req_data['success'] == '1' ? true : false;
553
-        $this->_template_args['success'] = $success;
554
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
555
-        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
556
-            EE_MAINTENANCE_ADMIN_URL);
557
-        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
558
-            EE_MAINTENANCE_ADMIN_URL);
559
-        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560
-            EE_MAINTENANCE_ADMIN_URL);
561
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
562
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563
-            $this->_template_args, true);
564
-        $this->display_admin_page_with_sidebar();
565
-    }
566
-
567
-
568
-
569
-    /**
570
-     * Resets the entire EE4 database.
571
-     * Currently basically only sets up ee4 database for a fresh install- doesn't
572
-     * actually clean out the old wp options, or cpts (although does erase old ee table data)
573
-     *
574
-     * @param boolean $nuke_old_ee4_data controls whether or not we
575
-     *                                   destroy the old ee4 data, or just try initializing ee4 default data
576
-     */
577
-    public function _reset_db($nuke_old_ee4_data = true)
578
-    {
579
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
580
-        if ($nuke_old_ee4_data) {
581
-            EEH_Activation::delete_all_espresso_cpt_data();
582
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
583
-            EEH_Activation::remove_cron_tasks();
584
-        }
585
-        //make sure when we reset the registry's config that it
586
-        //switches to using the new singleton
587
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
588
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
589
-        EE_System::instance()->redirect_to_about_ee();
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * Deletes ALL EE tables, Records, and Options from the database.
596
-     */
597
-    public function _delete_db()
598
-    {
599
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
600
-        EEH_Activation::delete_all_espresso_cpt_data();
601
-        EEH_Activation::delete_all_espresso_tables_and_data();
602
-        EEH_Activation::remove_cron_tasks();
603
-        EEH_Activation::deactivate_event_espresso();
604
-        wp_safe_redirect(admin_url('plugins.php'));
605
-        exit;
606
-    }
607
-
608
-
609
-
610
-    /**
611
-     * sets up EE4 to rerun the migrations from ee3 to ee4
612
-     */
613
-    public function _rerun_migration_from_ee3()
614
-    {
615
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
616
-        EEH_Activation::delete_all_espresso_cpt_data();
617
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
618
-        //set the db state to something that will require migrations
619
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
620
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
621
-        $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
622
-    }
623
-
624
-
625
-
626
-    //none of the below group are currently used for Gateway Settings
627
-    protected function _add_screen_options()
628
-    {
629
-    }
630
-
631
-
632
-
633
-    protected function _add_feature_pointers()
634
-    {
635
-    }
636
-
31
+	/**
32
+	 * @var EE_Datetime_Offset_Fix_Form
33
+	 */
34
+	protected $datetime_fix_offset_form;
35
+
36
+
37
+
38
+	protected function _init_page_props()
39
+	{
40
+		$this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
+		$this->page_label = EE_MAINTENANCE_LABEL;
42
+		$this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
+	}
45
+
46
+
47
+
48
+	protected function _ajax_hooks()
49
+	{
50
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
+	}
53
+
54
+
55
+
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
+		$this->_labels = array(
60
+			'buttons' => array(
61
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
+			),
64
+		);
65
+	}
66
+
67
+
68
+
69
+	protected function _set_page_routes()
70
+	{
71
+		$this->_page_routes = array(
72
+			'default'                             => array(
73
+				'func'       => '_maintenance',
74
+				'capability' => 'manage_options',
75
+			),
76
+			'change_maintenance_level'            => array(
77
+				'func'       => '_change_maintenance_level',
78
+				'capability' => 'manage_options',
79
+				'noheader'   => true,
80
+			),
81
+			'system_status'                       => array(
82
+				'func'       => '_system_status',
83
+				'capability' => 'manage_options',
84
+			),
85
+			'download_system_status' => array(
86
+				'func'       => '_download_system_status',
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			),
90
+			'send_migration_crash_report'         => array(
91
+				'func'       => '_send_migration_crash_report',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			),
95
+			'confirm_migration_crash_report_sent' => array(
96
+				'func'       => '_confirm_migration_crash_report_sent',
97
+				'capability' => 'manage_options',
98
+			),
99
+			'data_reset'                          => array(
100
+				'func'       => '_data_reset_and_delete',
101
+				'capability' => 'manage_options',
102
+			),
103
+			'reset_db'                            => array(
104
+				'func'       => '_reset_db',
105
+				'capability' => 'manage_options',
106
+				'noheader'   => true,
107
+				'args'       => array('nuke_old_ee4_data' => true),
108
+			),
109
+			'start_with_fresh_ee4_db'             => array(
110
+				'func'       => '_reset_db',
111
+				'capability' => 'manage_options',
112
+				'noheader'   => true,
113
+				'args'       => array('nuke_old_ee4_data' => false),
114
+			),
115
+			'delete_db'                           => array(
116
+				'func'       => '_delete_db',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			),
120
+			'rerun_migration_from_ee3'            => array(
121
+				'func'       => '_rerun_migration_from_ee3',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+			'reset_reservations'                  => array(
126
+				'func'       => '_reset_reservations',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+			'reset_capabilities'                  => array(
131
+				'func'       => '_reset_capabilities',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+			'reattempt_migration'                 => array(
136
+				'func'       => '_reattempt_migration',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			),
140
+			'datetime_tools' => array(
141
+				'func' => '_datetime_tools',
142
+				'capability' => 'manage_options'
143
+			),
144
+			'run_datetime_offset_fix' => array(
145
+				'func' => '_apply_datetime_offset',
146
+				'noheader' => true,
147
+				'headers_sent_route' => 'datetime_tools',
148
+				'capability' => 'manage_options'
149
+			)
150
+		);
151
+	}
152
+
153
+
154
+
155
+	protected function _set_page_config()
156
+	{
157
+		$this->_page_config = array(
158
+			'default'       => array(
159
+				'nav'           => array(
160
+					'label' => esc_html__('Maintenance', 'event_espresso'),
161
+					'order' => 10,
162
+				),
163
+				'require_nonce' => false,
164
+			),
165
+			'data_reset'    => array(
166
+				'nav'           => array(
167
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
168
+					'order' => 20,
169
+				),
170
+				'require_nonce' => false,
171
+			),
172
+			'datetime_tools' => array(
173
+				'nav' => array(
174
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
175
+					'order' => 25
176
+				),
177
+				'require_nonce' => false,
178
+			),
179
+			'system_status' => array(
180
+				'nav'           => array(
181
+					'label' => esc_html__("System Information", "event_espresso"),
182
+					'order' => 30,
183
+				),
184
+				'require_nonce' => false,
185
+			),
186
+		);
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
193
+	 * the migration scripts and all that UI.
194
+	 */
195
+	public function _maintenance()
196
+	{
197
+		//it all depends if we're in maintenance model level 1 (frontend-only) or
198
+		//level 2 (everything except maintenance page)
199
+		try {
200
+			//get the current maintenance level and check if
201
+			//we are removed
202
+			$mm = EE_Maintenance_Mode::instance()->level();
203
+			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
204
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
205
+				//we just took the site out of maintenance mode, so notify the user.
206
+				//unfortunately this message appears to be echoed on the NEXT page load...
207
+				//oh well, we should really be checking for this on addon deactivation anyways
208
+				EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
209
+					'event_espresso'));
210
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
211
+			}
212
+			//in case an exception is thrown while trying to handle migrations
213
+			switch (EE_Maintenance_Mode::instance()->level()) {
214
+				case EE_Maintenance_Mode::level_0_not_in_maintenance:
215
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
216
+					$show_maintenance_switch = true;
217
+					$show_backup_db_text = false;
218
+					$show_migration_progress = false;
219
+					$script_names = array();
220
+					$addons_should_be_upgraded_first = false;
221
+					break;
222
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
223
+					$show_maintenance_switch = false;
224
+					$show_migration_progress = true;
225
+					if (isset($this->_req_data['continue_migration'])) {
226
+						$show_backup_db_text = false;
227
+					} else {
228
+						$show_backup_db_text = true;
229
+					}
230
+					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()
231
+																	   ->check_for_applicable_data_migration_scripts();
232
+					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
233
+					$script_names = array();
234
+					$current_script = null;
235
+					foreach ($scripts_needing_to_run as $script) {
236
+						if ($script instanceof EE_Data_Migration_Script_Base) {
237
+							if ( ! $current_script) {
238
+								$current_script = $script;
239
+								$current_script->migration_page_hooks();
240
+							}
241
+							$script_names[] = $script->pretty_name();
242
+						}
243
+					}
244
+					break;
245
+			}
246
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
247
+			$exception_thrown = false;
248
+		} catch (EE_Error $e) {
249
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
250
+			//now, just so we can display the page correctly, make a error migration script stage object
251
+			//and also put the error on it. It only persists for the duration of this request
252
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
253
+			$most_recent_migration->add_error($e->getMessage());
254
+			$exception_thrown = true;
255
+		}
256
+		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
257
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
258
+		if ($exception_thrown
259
+			|| ($most_recent_migration
260
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
261
+				&& $most_recent_migration->is_broken()
262
+			)
263
+		) {
264
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
265
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267
+																						'success' => '0',
268
+			), EE_MAINTENANCE_ADMIN_URL);
269
+		} elseif ($addons_should_be_upgraded_first) {
270
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
271
+		} else {
272
+			if ($most_recent_migration
273
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
274
+				&& $most_recent_migration->can_continue()
275
+			) {
276
+				$show_backup_db_text = false;
277
+				$show_continue_current_migration_script = true;
278
+				$show_most_recent_migration = true;
279
+			} elseif (isset($this->_req_data['continue_migration'])) {
280
+				$show_most_recent_migration = true;
281
+				$show_continue_current_migration_script = false;
282
+			} else {
283
+				$show_most_recent_migration = false;
284
+				$show_continue_current_migration_script = false;
285
+			}
286
+			if (isset($current_script)) {
287
+				$migrates_to = $current_script->migrates_to_version();
288
+				$plugin_slug = $migrates_to['slug'];
289
+				$new_version = $migrates_to['version'];
290
+				$this->_template_args = array_merge($this->_template_args, array(
291
+					'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
292
+						isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
293
+					'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
294
+						$new_version, $plugin_slug) : null,
295
+				));
296
+			} else {
297
+				$this->_template_args['current_db_state'] = null;
298
+				$this->_template_args['next_db_state'] = null;
299
+			}
300
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
301
+			$this->_template_args = array_merge(
302
+				$this->_template_args,
303
+				array(
304
+					'show_most_recent_migration'             => $show_most_recent_migration,
305
+					//flag for showing the most recent migration's status and/or errors
306
+					'show_migration_progress'                => $show_migration_progress,
307
+					//flag for showing the option to run migrations and see their progress
308
+					'show_backup_db_text'                    => $show_backup_db_text,
309
+					//flag for showing text telling the user to backup their DB
310
+					'show_maintenance_switch'                => $show_maintenance_switch,
311
+					//flag for showing the option to change maintenance mode between levels 0 and 1
312
+					'script_names'                           => $script_names,
313
+					//array of names of scripts that have run
314
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
315
+					//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
316
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
317
+						EE_MAINTENANCE_ADMIN_URL),
318
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
319
+						EE_MAINTENANCE_ADMIN_URL),
320
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
321
+						EE_MAINTENANCE_ADMIN_URL),
322
+					'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
323
+						espresso_version()),
324
+				)
325
+			);
326
+			//make sure we have the form fields helper available. It usually is, but sometimes it isn't
327
+			//localize script stuff
328
+			wp_localize_script('ee-maintenance', 'ee_maintenance', array(
329
+				'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
330
+				'next'                             => esc_html__("Next", "event_espresso"),
331
+				'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
332
+				'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
333
+					"event_espresso"),
334
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
335
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
336
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337
+			));
338
+		}
339
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
340
+		//now render the migration options part, and put it in a variable
341
+		$migration_options_template_file = apply_filters(
342
+			'FHEE__ee_migration_page__migration_options_template',
343
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
344
+		);
345
+		$migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
346
+		$this->_template_args['migration_options_html'] = $migration_options_html;
347
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348
+			$this->_template_args, true);
349
+		$this->display_admin_page_with_sidebar();
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
356
+	 */
357
+	public function migration_step()
358
+	{
359
+		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
360
+		$this->_return_json();
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * Can be used by js when it notices a response with HTML in it in order
367
+	 * to log the malformed response
368
+	 */
369
+	public function add_error_to_migrations_ran()
370
+	{
371
+		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
372
+		$this->_template_args['data'] = array('ok' => true);
373
+		$this->_return_json();
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * changes the maintenance level, provided there are still no migration scripts that should run
380
+	 */
381
+	public function _change_maintenance_level()
382
+	{
383
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
384
+		if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
385
+			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
386
+			$success = true;
387
+		} else {
388
+			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
389
+			$success = false;
390
+		}
391
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * a tab with options for resetting and/or deleting EE data
398
+	 *
399
+	 * @throws \EE_Error
400
+	 * @throws \DomainException
401
+	 */
402
+	public function _data_reset_and_delete()
403
+	{
404
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
405
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406
+			'reset_reservations',
407
+			'reset_reservations',
408
+			array(),
409
+			'button button-primary',
410
+			'',
411
+			false
412
+		);
413
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
414
+			'reset_capabilities',
415
+			'reset_capabilities',
416
+			array(),
417
+			'button button-primary',
418
+			'',
419
+			false
420
+		);
421
+		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
422
+			array('action' => 'delete_db'),
423
+			EE_MAINTENANCE_ADMIN_URL
424
+		);
425
+		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
426
+			array('action' => 'reset_db'),
427
+			EE_MAINTENANCE_ADMIN_URL
428
+		);
429
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
430
+			$this->_template_path,
431
+			$this->_template_args,
432
+			true
433
+		);
434
+		$this->display_admin_page_with_sidebar();
435
+	}
436
+
437
+
438
+
439
+	protected function _reset_reservations()
440
+	{
441
+		if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442
+			EE_Error::add_success(
443
+				__(
444
+					'Ticket and datetime reserved counts have been successfully reset.',
445
+					'event_espresso'
446
+				)
447
+			);
448
+		} else {
449
+			EE_Error::add_success(
450
+				__(
451
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
452
+					'event_espresso'
453
+				)
454
+			);
455
+		}
456
+		$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
457
+	}
458
+
459
+
460
+
461
+	protected function _reset_capabilities()
462
+	{
463
+		EE_Registry::instance()->CAP->init_caps(true);
464
+		EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
465
+			'event_espresso'));
466
+		$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 * resets the DMSs so we can attempt to continue migrating after a fatal error
473
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
474
+	 * the fatal error in teh first place)
475
+	 */
476
+	protected function _reattempt_migration()
477
+	{
478
+		EE_Data_Migration_Manager::instance()->reattempt();
479
+		$this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * shows the big ol' System Information page
486
+	 */
487
+	public function _system_status()
488
+	{
489
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
490
+		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492
+			array(
493
+				'action' => 'download_system_status',
494
+			),
495
+			EE_MAINTENANCE_ADMIN_URL
496
+		);
497
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
498
+			$this->_template_args, true);
499
+		$this->display_admin_page_with_sidebar();
500
+	}
501
+
502
+	/**
503
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
504
+	 */
505
+	public function _download_system_status()
506
+	{
507
+		$status_info = EEM_System_Status::instance()->get_system_stati();
508
+		header( 'Content-Disposition: attachment' );
509
+		header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
510
+		echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
511
+		echo "<h1>System Information for " . site_url() . "</h1>";
512
+		echo EEH_Template::layout_array_as_table( $status_info );
513
+		die;
514
+	}
515
+
516
+
517
+
518
+	public function _send_migration_crash_report()
519
+	{
520
+		$from = $this->_req_data['from'];
521
+		$from_name = $this->_req_data['from_name'];
522
+		$body = $this->_req_data['body'];
523
+		try {
524
+			$success = wp_mail(EE_SUPPORT_EMAIL,
525
+				'Migration Crash Report',
526
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
527
+				array(
528
+					"from:$from_name<$from>",
529
+					//					'content-type:text/html charset=UTF-8'
530
+				));
531
+		} catch (Exception $e) {
532
+			$success = false;
533
+		}
534
+		$this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
535
+			esc_html__("sent", "event_espresso"),
536
+			array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
537
+	}
538
+
539
+
540
+
541
+	public function _confirm_migration_crash_report_sent()
542
+	{
543
+		try {
544
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
545
+		} catch (EE_Error $e) {
546
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
547
+			//now, just so we can display the page correctly, make a error migration script stage object
548
+			//and also put the error on it. It only persists for the duration of this request
549
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
550
+			$most_recent_migration->add_error($e->getMessage());
551
+		}
552
+		$success = $this->_req_data['success'] == '1' ? true : false;
553
+		$this->_template_args['success'] = $success;
554
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
555
+		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
556
+			EE_MAINTENANCE_ADMIN_URL);
557
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
558
+			EE_MAINTENANCE_ADMIN_URL);
559
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560
+			EE_MAINTENANCE_ADMIN_URL);
561
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
562
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563
+			$this->_template_args, true);
564
+		$this->display_admin_page_with_sidebar();
565
+	}
566
+
567
+
568
+
569
+	/**
570
+	 * Resets the entire EE4 database.
571
+	 * Currently basically only sets up ee4 database for a fresh install- doesn't
572
+	 * actually clean out the old wp options, or cpts (although does erase old ee table data)
573
+	 *
574
+	 * @param boolean $nuke_old_ee4_data controls whether or not we
575
+	 *                                   destroy the old ee4 data, or just try initializing ee4 default data
576
+	 */
577
+	public function _reset_db($nuke_old_ee4_data = true)
578
+	{
579
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
580
+		if ($nuke_old_ee4_data) {
581
+			EEH_Activation::delete_all_espresso_cpt_data();
582
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
583
+			EEH_Activation::remove_cron_tasks();
584
+		}
585
+		//make sure when we reset the registry's config that it
586
+		//switches to using the new singleton
587
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
588
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
589
+		EE_System::instance()->redirect_to_about_ee();
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * Deletes ALL EE tables, Records, and Options from the database.
596
+	 */
597
+	public function _delete_db()
598
+	{
599
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
600
+		EEH_Activation::delete_all_espresso_cpt_data();
601
+		EEH_Activation::delete_all_espresso_tables_and_data();
602
+		EEH_Activation::remove_cron_tasks();
603
+		EEH_Activation::deactivate_event_espresso();
604
+		wp_safe_redirect(admin_url('plugins.php'));
605
+		exit;
606
+	}
607
+
608
+
609
+
610
+	/**
611
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
612
+	 */
613
+	public function _rerun_migration_from_ee3()
614
+	{
615
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
616
+		EEH_Activation::delete_all_espresso_cpt_data();
617
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
618
+		//set the db state to something that will require migrations
619
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
620
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
621
+		$this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
622
+	}
623
+
624
+
625
+
626
+	//none of the below group are currently used for Gateway Settings
627
+	protected function _add_screen_options()
628
+	{
629
+	}
630
+
631
+
632
+
633
+	protected function _add_feature_pointers()
634
+	{
635
+	}
636
+
637 637
 
638 638
 
639
-    public function admin_init()
640
-    {
641
-    }
642
-
643
-
644
-
645
-    public function admin_notices()
646
-    {
647
-    }
648
-
639
+	public function admin_init()
640
+	{
641
+	}
642
+
643
+
644
+
645
+	public function admin_notices()
646
+	{
647
+	}
648
+
649 649
 
650 650
 
651
-    public function admin_footer_scripts()
652
-    {
653
-    }
651
+	public function admin_footer_scripts()
652
+	{
653
+	}
654 654
 
655 655
 
656 656
 
657
-    public function load_scripts_styles()
658
-    {
659
-        wp_enqueue_script('ee_admin_js');
657
+	public function load_scripts_styles()
658
+	{
659
+		wp_enqueue_script('ee_admin_js');
660 660
 //		wp_enqueue_media();
661 661
 //		wp_enqueue_script('media-upload');
662
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
663
-            EVENT_ESPRESSO_VERSION, true);
664
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
665
-            EVENT_ESPRESSO_VERSION);
666
-        wp_enqueue_style('espresso_maintenance');
667
-    }
662
+		wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
663
+			EVENT_ESPRESSO_VERSION, true);
664
+		wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
665
+			EVENT_ESPRESSO_VERSION);
666
+		wp_enqueue_style('espresso_maintenance');
667
+	}
668 668
 
669 669
 
670 670
 
671
-    public function load_scripts_styles_default()
672
-    {
673
-        //styles
671
+	public function load_scripts_styles_default()
672
+	{
673
+		//styles
674 674
 //		wp_enqueue_style('ee-text-links');
675 675
 //		//scripts
676 676
 //		wp_enqueue_script('ee-text-links');
677
-    }
678
-
679
-
680
-    protected function _datetime_tools()
681
-    {
682
-        $form_action = EE_Admin_Page::add_query_args_and_nonce(
683
-            array(
684
-                'action' => 'run_datetime_offset_fix',
685
-                'return_action' => $this->_req_action
686
-            ),
687
-            EE_MAINTENANCE_ADMIN_URL
688
-        );
689
-        $form = $this->_get_datetime_offset_fix_form();
690
-        $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
691
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
692
-                                                      . $form->get_html_and_js()
693
-                                                      . $form->form_close();
694
-        $this->display_admin_page_with_no_sidebar();
695
-    }
696
-
697
-
698
-
699
-    protected function _get_datetime_offset_fix_form()
700
-    {
701
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
703
-                array(
704
-                    'name' => 'datetime_offset_fix_option',
705
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706
-                    'subsections' => array(
707
-                        'title' => new EE_Form_Section_HTML(
708
-                            EEH_HTML::h2(
709
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
710
-                            )
711
-                        ),
712
-                        'explanation' => new EE_Form_Section_HTML(
713
-                            EEH_HTML::p(
714
-                                esc_html__(
715
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
716
-                                    'event_espresso'
717
-                                )
718
-                            )
719
-                            . EEH_HTML::p(
720
-                                esc_html__(
721
-                                    'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
722
-                                    'event_espresso'
723
-                                )
724
-                            )
725
-                        ),
726
-                        'offset_input' => new EE_Float_Input(
727
-                            array(
728
-                                'html_name' => 'offset_for_datetimes',
729
-                                'html_label_text' => esc_html__(
730
-                                    'Offset to apply (in hours):',
731
-                                    'event_espresso'
732
-                                ),
733
-                                'min_value' => '-12',
734
-                                'max_value' => '14',
735
-                                'step_value' => '.25',
736
-                                'default' => DatetimeOffsetFix::getOffset()
737
-                            )
738
-                        ),
739
-                        'submit' => new EE_Submit_Input(
740
-                            array(
741
-                                'html_label_text' => '',
742
-                                'default' => esc_html__('Apply Offset', 'event_espresso')
743
-                            )
744
-                        )
745
-                    )
746
-                )
747
-            );
748
-        }
749
-        return $this->datetime_fix_offset_form;
750
-    }
751
-
752
-
753
-    /**
754
-     * Callback for the run_datetime_offset_fix route.
755
-     * @throws EE_Error
756
-     */
757
-    protected function _apply_datetime_offset()
758
-    {
759
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
760
-            $form = $this->_get_datetime_offset_fix_form();
761
-            $form->receive_form_submission($this->_req_data);
762
-            if ($form->is_valid()) {
763
-                //save offset so batch processor can get it.
764
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
765
-                //redirect to batch tool
766
-                wp_redirect(
767
-                    EE_Admin_Page::add_query_args_and_nonce(
768
-                        array(
769
-                            'page' => 'espresso_batch',
770
-                            'batch' => 'job',
771
-                            'label' => esc_html__('Applying Offset', 'event_espresso'),
772
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
773
-                            'return_url' => urlencode(home_url(add_query_arg(null, null))),
774
-                        ),
775
-                        admin_url()
776
-                    )
777
-                );
778
-                exit;
779
-            }
780
-        }
781
-    }
677
+	}
678
+
679
+
680
+	protected function _datetime_tools()
681
+	{
682
+		$form_action = EE_Admin_Page::add_query_args_and_nonce(
683
+			array(
684
+				'action' => 'run_datetime_offset_fix',
685
+				'return_action' => $this->_req_action
686
+			),
687
+			EE_MAINTENANCE_ADMIN_URL
688
+		);
689
+		$form = $this->_get_datetime_offset_fix_form();
690
+		$this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso');
691
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
692
+													  . $form->get_html_and_js()
693
+													  . $form->form_close();
694
+		$this->display_admin_page_with_no_sidebar();
695
+	}
696
+
697
+
698
+
699
+	protected function _get_datetime_offset_fix_form()
700
+	{
701
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
+			$this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
703
+				array(
704
+					'name' => 'datetime_offset_fix_option',
705
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706
+					'subsections' => array(
707
+						'title' => new EE_Form_Section_HTML(
708
+							EEH_HTML::h2(
709
+								esc_html__('Datetime Offset Tool', 'event_espresso')
710
+							)
711
+						),
712
+						'explanation' => new EE_Form_Section_HTML(
713
+							EEH_HTML::p(
714
+								esc_html__(
715
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
716
+									'event_espresso'
717
+								)
718
+							)
719
+							. EEH_HTML::p(
720
+								esc_html__(
721
+									'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
722
+									'event_espresso'
723
+								)
724
+							)
725
+						),
726
+						'offset_input' => new EE_Float_Input(
727
+							array(
728
+								'html_name' => 'offset_for_datetimes',
729
+								'html_label_text' => esc_html__(
730
+									'Offset to apply (in hours):',
731
+									'event_espresso'
732
+								),
733
+								'min_value' => '-12',
734
+								'max_value' => '14',
735
+								'step_value' => '.25',
736
+								'default' => DatetimeOffsetFix::getOffset()
737
+							)
738
+						),
739
+						'submit' => new EE_Submit_Input(
740
+							array(
741
+								'html_label_text' => '',
742
+								'default' => esc_html__('Apply Offset', 'event_espresso')
743
+							)
744
+						)
745
+					)
746
+				)
747
+			);
748
+		}
749
+		return $this->datetime_fix_offset_form;
750
+	}
751
+
752
+
753
+	/**
754
+	 * Callback for the run_datetime_offset_fix route.
755
+	 * @throws EE_Error
756
+	 */
757
+	protected function _apply_datetime_offset()
758
+	{
759
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
760
+			$form = $this->_get_datetime_offset_fix_form();
761
+			$form->receive_form_submission($this->_req_data);
762
+			if ($form->is_valid()) {
763
+				//save offset so batch processor can get it.
764
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
765
+				//redirect to batch tool
766
+				wp_redirect(
767
+					EE_Admin_Page::add_query_args_and_nonce(
768
+						array(
769
+							'page' => 'espresso_batch',
770
+							'batch' => 'job',
771
+							'label' => esc_html__('Applying Offset', 'event_espresso'),
772
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
773
+							'return_url' => urlencode(home_url(add_query_arg(null, null))),
774
+						),
775
+						admin_url()
776
+					)
777
+				);
778
+				exit;
779
+			}
780
+		}
781
+	}
782 782
 } //end Maintenance_Admin_Page class
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     public static function instance()
33 33
     {
34 34
         // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Admin) {
35
+        if ( ! self::$_instance instanceof EE_Admin) {
36 36
             self::$_instance = new self();
37 37
         }
38 38
         return self::$_instance;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function _define_all_constants()
93 93
     {
94
-        if (! defined('EE_ADMIN_URL')) {
95
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
94
+        if ( ! defined('EE_ADMIN_URL')) {
95
+            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
96
+            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
97
+            define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS);
98
+            define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
99 99
             define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100 100
         }
101 101
     }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         // set $main_file in stone
115 115
         static $main_file;
116 116
         // if $main_file is not set yet
117
-        if (! $main_file) {
117
+        if ( ! $main_file) {
118 118
             $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119 119
         }
120 120
         if ($plugin === $main_file) {
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
     public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166 166
     {
167 167
         return array(
168
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
168
+            'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS,
169
+            'about'       => EE_ADMIN_PAGES.'about'.DS,
170
+            'support'     => EE_ADMIN_PAGES.'support'.DS,
171 171
         );
172 172
     }
173 173
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
             add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196 196
         }
197 197
         // run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
198
+        if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199 199
             try {
200 200
                 //this loads the controller for the admin pages which will setup routing etc
201 201
                 EE_Registry::instance()->load_core('Admin_Page_Loader');
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function enable_hidden_ee_nav_menu_metaboxes()
248 248
     {
249 249
         global $wp_meta_boxes, $pagenow;
250
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
250
+        if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251 251
             return;
252 252
         }
253 253
         $user = wp_get_current_user();
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      */
319 319
     public function modify_edit_post_link($link, $id)
320 320
     {
321
-        if (! $post = get_post($id)) {
321
+        if ( ! $post = get_post($id)) {
322 322
             return $link;
323 323
         }
324 324
         if ($post->post_type === 'espresso_attendees') {
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 
545 545
         //loop through to remove any critical pages from the array.
546 546
         foreach ($critical_pages as $page_id) {
547
-            $needle = 'value="' . $page_id . '"';
547
+            $needle = 'value="'.$page_id.'"';
548 548
             foreach ($split_output as $key => $haystack) {
549 549
                 if (strpos($haystack, $needle) !== false) {
550 550
                     unset($split_output[$key]);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         // calls.
571 571
         wp_enqueue_script(
572 572
             'ee-inject-wp',
573
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
573
+            EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js',
574 574
             array('jquery'),
575 575
             EVENT_ESPRESSO_VERSION,
576 576
             true
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
         // register cookie script for future dependencies
579 579
         wp_register_script(
580 580
             'jquery-cookie',
581
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
581
+            EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js',
582 582
             array('jquery'),
583 583
             '2.1',
584 584
             true
@@ -587,16 +587,16 @@  discard block
 block discarded – undo
587 587
         // via: add_filter('FHEE_load_joyride', '__return_true' );
588 588
         if (apply_filters('FHEE_load_joyride', false)) {
589 589
             //joyride style
590
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
590
+            wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
591 591
             wp_register_style(
592 592
                 'ee-joyride-css',
593
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
593
+                EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css',
594 594
                 array('joyride-css'),
595 595
                 EVENT_ESPRESSO_VERSION
596 596
             );
597 597
             wp_register_script(
598 598
                 'joyride-modernizr',
599
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
599
+                EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js',
600 600
                 array(),
601 601
                 '2.1',
602 602
                 true
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
             //joyride JS
605 605
             wp_register_script(
606 606
                 'jquery-joyride',
607
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
607
+                EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js',
608 608
                 array('jquery-cookie', 'joyride-modernizr'),
609 609
                 '2.1',
610 610
                 true
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
     public function get_persistent_admin_notices()
658 658
     {
659 659
         // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
660
-        $args       = array(
660
+        $args = array(
661 661
             'page'   => EE_Registry::instance()->REQ->is_set('page')
662 662
                 ? EE_Registry::instance()->REQ->get('page')
663 663
                 : '',
@@ -704,21 +704,21 @@  discard block
 block discarded – undo
704 704
                 ),
705 705
             )
706 706
         );
707
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
707
+        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
708 708
             array('page' => 'espresso_registrations'),
709 709
             admin_url('admin.php')
710 710
         );
711
-        $items['registrations']['text']  = sprintf(
711
+        $items['registrations']['text'] = sprintf(
712 712
             _n('%s Registration', '%s Registrations', $registrations),
713 713
             number_format_i18n($registrations)
714 714
         );
715 715
         $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
716 716
 
717
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
717
+        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
718 718
 
719 719
         foreach ($items as $type => $item_properties) {
720 720
             $elements[] = sprintf(
721
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
721
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
722 722
                 $item_properties['url'],
723 723
                 $item_properties['title'],
724 724
                 $item_properties['text']
@@ -744,10 +744,10 @@  discard block
 block discarded – undo
744 744
         // check for date_format or time_format
745 745
         switch ($option) {
746 746
             case 'date_format':
747
-                $date_time_format = $value . ' ' . get_option('time_format');
747
+                $date_time_format = $value.' '.get_option('time_format');
748 748
                 break;
749 749
             case 'time_format':
750
-                $date_time_format = get_option('date_format') . ' ' . $value;
750
+                $date_time_format = get_option('date_format').' '.$value;
751 751
                 break;
752 752
             default:
753 753
                 $date_time_format = false;
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 
771 771
 
772 772
                 foreach ($error_msg as $error) {
773
-                    $msg .= '<li>' . $error . '</li>';
773
+                    $msg .= '<li>'.$error.'</li>';
774 774
                 }
775 775
 
776 776
                 $msg .= '</ul></p><p>'
Please login to merge, or discard this patch.
Indentation   +848 added lines, -848 removed lines patch added patch discarded remove patch
@@ -15,395 +15,395 @@  discard block
 block discarded – undo
15 15
 final class EE_Admin implements InterminableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @access private
20
-     * @var EE_Admin $_instance
21
-     */
22
-    private static $_instance;
23
-
24
-
25
-    /**
26
-     *@ singleton method used to instantiate class object
27
-     *@ access public
28
-     *@ return class instance
29
-     *
30
-     * @throws \EE_Error
31
-     */
32
-    public static function instance()
33
-    {
34
-        // check if class object is instantiated
35
-        if (! self::$_instance instanceof EE_Admin) {
36
-            self::$_instance = new self();
37
-        }
38
-        return self::$_instance;
39
-    }
40
-
41
-
42
-    /**
43
-     * @return EE_Admin
44
-     * @throws EE_Error
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     * class constructor
55
-     *
56
-     * @throws \EE_Error
57
-     */
58
-    protected function __construct()
59
-    {
60
-        // define global EE_Admin constants
61
-        $this->_define_all_constants();
62
-        // set autoloaders for our admin page classes based on included path information
63
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
64
-        // admin hooks
65
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
66
-        // load EE_Request_Handler early
67
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
68
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
69
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
71
-        add_action('admin_init', array($this, 'admin_init'), 100);
72
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
73
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
74
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
75
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
76
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
77
-
78
-        //reset Environment config (we only do this on admin page loads);
79
-        EE_Registry::instance()->CFG->environment->recheck_values();
80
-
81
-        do_action('AHEE__EE_Admin__loaded');
82
-    }
83
-
84
-
85
-    /**
86
-     * _define_all_constants
87
-     * define constants that are set globally for all admin pages
88
-     *
89
-     * @access private
90
-     * @return void
91
-     */
92
-    private function _define_all_constants()
93
-    {
94
-        if (! defined('EE_ADMIN_URL')) {
95
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
99
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     *    filter_plugin_actions - adds links to the Plugins page listing
106
-     *
107
-     * @access    public
108
-     * @param    array  $links
109
-     * @param    string $plugin
110
-     * @return    array
111
-     */
112
-    public function filter_plugin_actions($links, $plugin)
113
-    {
114
-        // set $main_file in stone
115
-        static $main_file;
116
-        // if $main_file is not set yet
117
-        if (! $main_file) {
118
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119
-        }
120
-        if ($plugin === $main_file) {
121
-            // compare current plugin to this one
122
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
123
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
124
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
125
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
126
-                                    . '</a>';
127
-                array_unshift($links, $maintenance_link);
128
-            } else {
129
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
130
-                                     . esc_html__('Settings', 'event_espresso')
131
-                                     . '</a>';
132
-                $events_link       = '<a href="admin.php?page=espresso_events">'
133
-                                     . esc_html__('Events', 'event_espresso')
134
-                                     . '</a>';
135
-                // add before other links
136
-                array_unshift($links, $org_settings_link, $events_link);
137
-            }
138
-        }
139
-        return $links;
140
-    }
141
-
142
-
143
-    /**
144
-     *    _get_request
145
-     *
146
-     * @access public
147
-     * @return void
148
-     * @throws EE_Error
149
-     * @throws ReflectionException
150
-     */
151
-    public function get_request()
152
-    {
153
-        EE_Registry::instance()->load_core('Request_Handler');
154
-        EE_Registry::instance()->load_core('CPT_Strategy');
155
-    }
156
-
157
-
158
-    /**
159
-     *    hide_admin_pages_except_maintenance_mode
160
-     *
161
-     * @access public
162
-     * @param array $admin_page_folder_names
163
-     * @return array
164
-     */
165
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166
-    {
167
-        return array(
168
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
171
-        );
172
-    }
173
-
174
-
175
-    /**
176
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
177
-     * EE_Front_Controller's init phases have run
178
-     *
179
-     * @access public
180
-     * @return void
181
-     * @throws EE_Error
182
-     * @throws ReflectionException
183
-     */
184
-    public function init()
185
-    {
186
-        //only enable most of the EE_Admin IF we're not in full maintenance mode
187
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
188
-            //ok so we want to enable the entire admin
189
-            add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
-            add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
-            add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192
-            //at a glance dashboard widget
193
-            add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194
-            //filter for get_edit_post_link used on comments for custom post types
195
-            add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196
-        }
197
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199
-            try {
200
-                //this loads the controller for the admin pages which will setup routing etc
201
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
202
-            } catch (EE_Error $e) {
203
-                $e->get_error();
204
-            }
205
-        }
206
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207
-        //make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210
-        //exclude EE critical pages from all nav menus and wp_list_pages
211
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212
-    }
213
-
214
-
215
-    /**
216
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
217
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
218
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
219
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
220
-     * normal property on the post_type object.  It's found ONLY in this particular context.
221
-     *
222
-     * @param  object $post_type WP post type object
223
-     * @return object            WP post type object
224
-     */
225
-    public function remove_pages_from_nav_menu($post_type)
226
-    {
227
-        //if this isn't the "pages" post type let's get out
228
-        if ($post_type->name !== 'page') {
229
-            return $post_type;
230
-        }
231
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
232
-
233
-        $post_type->_default_query = array(
234
-            'post__not_in' => $critical_pages,
235
-        );
236
-        return $post_type;
237
-    }
238
-
239
-
240
-    /**
241
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
242
-     * metaboxes get shown as well
243
-     *
244
-     * @access public
245
-     * @return void
246
-     */
247
-    public function enable_hidden_ee_nav_menu_metaboxes()
248
-    {
249
-        global $wp_meta_boxes, $pagenow;
250
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251
-            return;
252
-        }
253
-        $user = wp_get_current_user();
254
-        //has this been done yet?
255
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
256
-            return;
257
-        }
258
-
259
-        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
260
-        $initial_meta_boxes = apply_filters(
261
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
262
-            array(
263
-                'nav-menu-theme-locations',
264
-                'add-page',
265
-                'add-custom-links',
266
-                'add-category',
267
-                'add-espresso_events',
268
-                'add-espresso_venues',
269
-                'add-espresso_event_categories',
270
-                'add-espresso_venue_categories',
271
-                'add-post-type-post',
272
-                'add-post-type-page',
273
-            )
274
-        );
275
-
276
-        if (is_array($hidden_meta_boxes)) {
277
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
278
-                if (in_array($meta_box_id, $initial_meta_boxes)) {
279
-                    unset($hidden_meta_boxes[$key]);
280
-                }
281
-            }
282
-        }
283
-
284
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
285
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
286
-    }
287
-
288
-
289
-    /**
290
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
291
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
292
-     *
293
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
294
-     *         addons etc.
295
-     * @access public
296
-     * @return void
297
-     */
298
-    public function register_custom_nav_menu_boxes()
299
-    {
300
-        add_meta_box(
301
-            'add-extra-nav-menu-pages',
302
-            esc_html__('Event Espresso Pages', 'event_espresso'),
303
-            array($this, 'ee_cpt_archive_pages'),
304
-            'nav-menus',
305
-            'side',
306
-            'core'
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
313
-     *
314
-     * @since   4.3.0
315
-     * @param string $link the original link generated by wp
316
-     * @param int    $id   post id
317
-     * @return string  the (maybe) modified link
318
-     */
319
-    public function modify_edit_post_link($link, $id)
320
-    {
321
-        if (! $post = get_post($id)) {
322
-            return $link;
323
-        }
324
-        if ($post->post_type === 'espresso_attendees') {
325
-            $query_args = array(
326
-                'action' => 'edit_attendee',
327
-                'post'   => $id,
328
-            );
329
-            return EEH_URL::add_query_args_and_nonce(
330
-                $query_args,
331
-                admin_url('admin.php?page=espresso_registrations')
332
-            );
333
-        }
334
-        return $link;
335
-    }
336
-
337
-
338
-    public function ee_cpt_archive_pages()
339
-    {
340
-        global $nav_menu_selected_id;
341
-
342
-        $db_fields   = false;
343
-        $walker      = new Walker_Nav_Menu_Checklist($db_fields);
344
-        $current_tab = 'event-archives';
345
-
346
-        /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
18
+	/**
19
+	 * @access private
20
+	 * @var EE_Admin $_instance
21
+	 */
22
+	private static $_instance;
23
+
24
+
25
+	/**
26
+	 *@ singleton method used to instantiate class object
27
+	 *@ access public
28
+	 *@ return class instance
29
+	 *
30
+	 * @throws \EE_Error
31
+	 */
32
+	public static function instance()
33
+	{
34
+		// check if class object is instantiated
35
+		if (! self::$_instance instanceof EE_Admin) {
36
+			self::$_instance = new self();
37
+		}
38
+		return self::$_instance;
39
+	}
40
+
41
+
42
+	/**
43
+	 * @return EE_Admin
44
+	 * @throws EE_Error
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 * class constructor
55
+	 *
56
+	 * @throws \EE_Error
57
+	 */
58
+	protected function __construct()
59
+	{
60
+		// define global EE_Admin constants
61
+		$this->_define_all_constants();
62
+		// set autoloaders for our admin page classes based on included path information
63
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
64
+		// admin hooks
65
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
66
+		// load EE_Request_Handler early
67
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
68
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
69
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
71
+		add_action('admin_init', array($this, 'admin_init'), 100);
72
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
73
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
74
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
75
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
76
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
77
+
78
+		//reset Environment config (we only do this on admin page loads);
79
+		EE_Registry::instance()->CFG->environment->recheck_values();
80
+
81
+		do_action('AHEE__EE_Admin__loaded');
82
+	}
83
+
84
+
85
+	/**
86
+	 * _define_all_constants
87
+	 * define constants that are set globally for all admin pages
88
+	 *
89
+	 * @access private
90
+	 * @return void
91
+	 */
92
+	private function _define_all_constants()
93
+	{
94
+		if (! defined('EE_ADMIN_URL')) {
95
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
96
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
97
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
98
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
99
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 *    filter_plugin_actions - adds links to the Plugins page listing
106
+	 *
107
+	 * @access    public
108
+	 * @param    array  $links
109
+	 * @param    string $plugin
110
+	 * @return    array
111
+	 */
112
+	public function filter_plugin_actions($links, $plugin)
113
+	{
114
+		// set $main_file in stone
115
+		static $main_file;
116
+		// if $main_file is not set yet
117
+		if (! $main_file) {
118
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
119
+		}
120
+		if ($plugin === $main_file) {
121
+			// compare current plugin to this one
122
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
123
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
124
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
125
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
126
+									. '</a>';
127
+				array_unshift($links, $maintenance_link);
128
+			} else {
129
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
130
+									 . esc_html__('Settings', 'event_espresso')
131
+									 . '</a>';
132
+				$events_link       = '<a href="admin.php?page=espresso_events">'
133
+									 . esc_html__('Events', 'event_espresso')
134
+									 . '</a>';
135
+				// add before other links
136
+				array_unshift($links, $org_settings_link, $events_link);
137
+			}
138
+		}
139
+		return $links;
140
+	}
141
+
142
+
143
+	/**
144
+	 *    _get_request
145
+	 *
146
+	 * @access public
147
+	 * @return void
148
+	 * @throws EE_Error
149
+	 * @throws ReflectionException
150
+	 */
151
+	public function get_request()
152
+	{
153
+		EE_Registry::instance()->load_core('Request_Handler');
154
+		EE_Registry::instance()->load_core('CPT_Strategy');
155
+	}
156
+
157
+
158
+	/**
159
+	 *    hide_admin_pages_except_maintenance_mode
160
+	 *
161
+	 * @access public
162
+	 * @param array $admin_page_folder_names
163
+	 * @return array
164
+	 */
165
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
166
+	{
167
+		return array(
168
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
169
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
170
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
171
+		);
172
+	}
173
+
174
+
175
+	/**
176
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
177
+	 * EE_Front_Controller's init phases have run
178
+	 *
179
+	 * @access public
180
+	 * @return void
181
+	 * @throws EE_Error
182
+	 * @throws ReflectionException
183
+	 */
184
+	public function init()
185
+	{
186
+		//only enable most of the EE_Admin IF we're not in full maintenance mode
187
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
188
+			//ok so we want to enable the entire admin
189
+			add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
+			add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
+			add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192
+			//at a glance dashboard widget
193
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194
+			//filter for get_edit_post_link used on comments for custom post types
195
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196
+		}
197
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
198
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199
+			try {
200
+				//this loads the controller for the admin pages which will setup routing etc
201
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
202
+			} catch (EE_Error $e) {
203
+				$e->get_error();
204
+			}
205
+		}
206
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207
+		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210
+		//exclude EE critical pages from all nav menus and wp_list_pages
211
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212
+	}
213
+
214
+
215
+	/**
216
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
217
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
218
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
219
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
220
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
221
+	 *
222
+	 * @param  object $post_type WP post type object
223
+	 * @return object            WP post type object
224
+	 */
225
+	public function remove_pages_from_nav_menu($post_type)
226
+	{
227
+		//if this isn't the "pages" post type let's get out
228
+		if ($post_type->name !== 'page') {
229
+			return $post_type;
230
+		}
231
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
232
+
233
+		$post_type->_default_query = array(
234
+			'post__not_in' => $critical_pages,
235
+		);
236
+		return $post_type;
237
+	}
238
+
239
+
240
+	/**
241
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
242
+	 * metaboxes get shown as well
243
+	 *
244
+	 * @access public
245
+	 * @return void
246
+	 */
247
+	public function enable_hidden_ee_nav_menu_metaboxes()
248
+	{
249
+		global $wp_meta_boxes, $pagenow;
250
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
251
+			return;
252
+		}
253
+		$user = wp_get_current_user();
254
+		//has this been done yet?
255
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
256
+			return;
257
+		}
258
+
259
+		$hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
260
+		$initial_meta_boxes = apply_filters(
261
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
262
+			array(
263
+				'nav-menu-theme-locations',
264
+				'add-page',
265
+				'add-custom-links',
266
+				'add-category',
267
+				'add-espresso_events',
268
+				'add-espresso_venues',
269
+				'add-espresso_event_categories',
270
+				'add-espresso_venue_categories',
271
+				'add-post-type-post',
272
+				'add-post-type-page',
273
+			)
274
+		);
275
+
276
+		if (is_array($hidden_meta_boxes)) {
277
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
278
+				if (in_array($meta_box_id, $initial_meta_boxes)) {
279
+					unset($hidden_meta_boxes[$key]);
280
+				}
281
+			}
282
+		}
283
+
284
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
285
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
286
+	}
287
+
288
+
289
+	/**
290
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
291
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
292
+	 *
293
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
294
+	 *         addons etc.
295
+	 * @access public
296
+	 * @return void
297
+	 */
298
+	public function register_custom_nav_menu_boxes()
299
+	{
300
+		add_meta_box(
301
+			'add-extra-nav-menu-pages',
302
+			esc_html__('Event Espresso Pages', 'event_espresso'),
303
+			array($this, 'ee_cpt_archive_pages'),
304
+			'nav-menus',
305
+			'side',
306
+			'core'
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
313
+	 *
314
+	 * @since   4.3.0
315
+	 * @param string $link the original link generated by wp
316
+	 * @param int    $id   post id
317
+	 * @return string  the (maybe) modified link
318
+	 */
319
+	public function modify_edit_post_link($link, $id)
320
+	{
321
+		if (! $post = get_post($id)) {
322
+			return $link;
323
+		}
324
+		if ($post->post_type === 'espresso_attendees') {
325
+			$query_args = array(
326
+				'action' => 'edit_attendee',
327
+				'post'   => $id,
328
+			);
329
+			return EEH_URL::add_query_args_and_nonce(
330
+				$query_args,
331
+				admin_url('admin.php?page=espresso_registrations')
332
+			);
333
+		}
334
+		return $link;
335
+	}
336
+
337
+
338
+	public function ee_cpt_archive_pages()
339
+	{
340
+		global $nav_menu_selected_id;
341
+
342
+		$db_fields   = false;
343
+		$walker      = new Walker_Nav_Menu_Checklist($db_fields);
344
+		$current_tab = 'event-archives';
345
+
346
+		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
347 347
             $current_tab = 'search';
348 348
         }/**/
349 349
 
350
-        $removed_args = array(
351
-            'action',
352
-            'customlink-tab',
353
-            'edit-menu-item',
354
-            'menu-item',
355
-            'page-tab',
356
-            '_wpnonce',
357
-        );
350
+		$removed_args = array(
351
+			'action',
352
+			'customlink-tab',
353
+			'edit-menu-item',
354
+			'menu-item',
355
+			'page-tab',
356
+			'_wpnonce',
357
+		);
358 358
 
359
-        ?>
359
+		?>
360 360
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
361 361
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
362 362
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
363 363
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
364 364
                        href="<?php if ($nav_menu_selected_id) {
365
-                            echo esc_url(
366
-                                add_query_arg(
367
-                                    'extra-nav-menu-pages-tab',
368
-                                    'event-archives',
369
-                                    remove_query_arg($removed_args)
370
-                                )
371
-                            );
372
-                       } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
365
+							echo esc_url(
366
+								add_query_arg(
367
+									'extra-nav-menu-pages-tab',
368
+									'event-archives',
369
+									remove_query_arg($removed_args)
370
+								)
371
+							);
372
+					   } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
373 373
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
374 374
                     </a>
375 375
                 </li>
376 376
 
377 377
                 <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
378
-                echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
379
-                ?>">
378
+				echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
379
+				?>">
380 380
                     <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
381 381
                         <?php
382
-                        $pages          = $this->_get_extra_nav_menu_pages_items();
383
-                        $args['walker'] = $walker;
384
-                        echo walk_nav_menu_tree(
385
-                            array_map(
386
-                                array($this, '_setup_extra_nav_menu_pages_items'),
387
-                                $pages
388
-                            ),
389
-                            0,
390
-                            (object) $args
391
-                        );
392
-                        ?>
382
+						$pages          = $this->_get_extra_nav_menu_pages_items();
383
+						$args['walker'] = $walker;
384
+						echo walk_nav_menu_tree(
385
+							array_map(
386
+								array($this, '_setup_extra_nav_menu_pages_items'),
387
+								$pages
388
+							),
389
+							0,
390
+							(object) $args
391
+						);
392
+						?>
393 393
                     </ul>
394 394
                 </div><!-- /.tabs-panel -->
395 395
 
396 396
                 <p class="button-controls">
397 397
                 <span class="list-controls">
398 398
                     <a href="<?php
399
-                    echo esc_url(add_query_arg(
400
-                        array(
401
-                            'extra-nav-menu-pages-tab' => 'event-archives',
402
-                            'selectall'                => 1,
403
-                        ),
404
-                        remove_query_arg($removed_args)
405
-                    ));
406
-                    ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
399
+					echo esc_url(add_query_arg(
400
+						array(
401
+							'extra-nav-menu-pages-tab' => 'event-archives',
402
+							'selectall'                => 1,
403
+						),
404
+						remove_query_arg($removed_args)
405
+					));
406
+					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
407 407
                 </span>
408 408
                 <span class="add-to-menu">
409 409
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -416,485 +416,485 @@  discard block
 block discarded – undo
416 416
 
417 417
         </div><!-- /.posttypediv -->
418 418
         <?php
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns an array of event archive nav items.
424
-     *
425
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
426
-     *        method we use for getting the extra nav menu items
427
-     * @return array
428
-     */
429
-    private function _get_extra_nav_menu_pages_items()
430
-    {
431
-        $menuitems[] = array(
432
-            'title'       => esc_html__('Event List', 'event_espresso'),
433
-            'url'         => get_post_type_archive_link('espresso_events'),
434
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
435
-        );
436
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
437
-    }
438
-
439
-
440
-    /**
441
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
442
-     * the properties and converts it to the menu item object.
443
-     *
444
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
445
-     * @param $menu_item_values
446
-     * @return stdClass
447
-     */
448
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
449
-    {
450
-        $menu_item = new stdClass();
451
-        $keys      = array(
452
-            'ID'               => 0,
453
-            'db_id'            => 0,
454
-            'menu_item_parent' => 0,
455
-            'object_id'        => -1,
456
-            'post_parent'      => 0,
457
-            'type'             => 'custom',
458
-            'object'           => '',
459
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
460
-            'title'            => '',
461
-            'url'              => '',
462
-            'target'           => '',
463
-            'attr_title'       => '',
464
-            'description'      => '',
465
-            'classes'          => array(),
466
-            'xfn'              => '',
467
-        );
468
-
469
-        foreach ($keys as $key => $value) {
470
-            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
471
-        }
472
-        return $menu_item;
473
-    }
474
-
475
-
476
-    /**
477
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
478
-     * EE_Admin_Page route is called.
479
-     *
480
-     * @return void
481
-     */
482
-    public function route_admin_request()
483
-    {
484
-    }
485
-
486
-
487
-    /**
488
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
489
-     *
490
-     * @return void
491
-     */
492
-    public function wp_loaded()
493
-    {
494
-    }
495
-
496
-
497
-    /**
498
-     * admin_init
499
-     *
500
-     * @access public
501
-     * @return void
502
-     * @throws EE_Error
503
-     * @throws ReflectionException
504
-     */
505
-    public function admin_init()
506
-    {
507
-
508
-        /**
509
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
510
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
511
-         * - check if doing post processing.
512
-         * - check if doing post processing of one of EE CPTs
513
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
514
-         */
515
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
516
-            EE_Registry::instance()->load_core('Register_CPTs');
517
-            EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
518
-        }
519
-
520
-
521
-        /**
522
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
523
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
524
-         * Pages" tab in the EE General Settings Admin page.
525
-         * This is for user-proofing.
526
-         */
527
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
528
-    }
529
-
530
-
531
-    /**
532
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
533
-     *
534
-     * @param string $output Current output.
535
-     * @return string
536
-     */
537
-    public function modify_dropdown_pages($output)
538
-    {
539
-        //get critical pages
540
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
541
-
542
-        //split current output by line break for easier parsing.
543
-        $split_output = explode("\n", $output);
544
-
545
-        //loop through to remove any critical pages from the array.
546
-        foreach ($critical_pages as $page_id) {
547
-            $needle = 'value="' . $page_id . '"';
548
-            foreach ($split_output as $key => $haystack) {
549
-                if (strpos($haystack, $needle) !== false) {
550
-                    unset($split_output[$key]);
551
-                }
552
-            }
553
-        }
554
-
555
-        //replace output with the new contents
556
-        return implode("\n", $split_output);
557
-    }
558
-
559
-
560
-    /**
561
-     * enqueue all admin scripts that need loaded for admin pages
562
-     *
563
-     * @access public
564
-     * @return void
565
-     */
566
-    public function enqueue_admin_scripts()
567
-    {
568
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
569
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
570
-        // calls.
571
-        wp_enqueue_script(
572
-            'ee-inject-wp',
573
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
574
-            array('jquery'),
575
-            EVENT_ESPRESSO_VERSION,
576
-            true
577
-        );
578
-        // register cookie script for future dependencies
579
-        wp_register_script(
580
-            'jquery-cookie',
581
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
582
-            array('jquery'),
583
-            '2.1',
584
-            true
585
-        );
586
-        //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
587
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
588
-        if (apply_filters('FHEE_load_joyride', false)) {
589
-            //joyride style
590
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
591
-            wp_register_style(
592
-                'ee-joyride-css',
593
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
594
-                array('joyride-css'),
595
-                EVENT_ESPRESSO_VERSION
596
-            );
597
-            wp_register_script(
598
-                'joyride-modernizr',
599
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
600
-                array(),
601
-                '2.1',
602
-                true
603
-            );
604
-            //joyride JS
605
-            wp_register_script(
606
-                'jquery-joyride',
607
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
608
-                array('jquery-cookie', 'joyride-modernizr'),
609
-                '2.1',
610
-                true
611
-            );
612
-            // wanna go for a joyride?
613
-            wp_enqueue_style('ee-joyride-css');
614
-            wp_enqueue_script('jquery-joyride');
615
-        }
616
-    }
617
-
618
-
619
-    /**
620
-     *    display_admin_notices
621
-     *
622
-     * @access    public
623
-     * @return    string
624
-     */
625
-    public function display_admin_notices()
626
-    {
627
-        //add non-dismissable notice for datetime changes.  Only valid if EE version is greater than 4.9.46.p and the
628
-        // site does not have a timezone_string set.
629
-        if (EE_Register_Addon::_meets_min_core_version_requirement(
630
-                '4.9.46.p'
631
-            )
632
-            && ! get_option('timezone_string')
633
-        ) {
634
-            EE_Error::add_attention(
635
-                sprintf(
636
-                    esc_html__(
637
-                        '%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website.  Read more about it %3$shere%4$s.',
638
-                        'event_espresso'
639
-                    ),
640
-                    '<strong>',
641
-                    '</strong>',
642
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
643
-                    '</a>'
644
-                )
645
-            );
646
-        }
647
-        echo EE_Error::get_notices();
648
-    }
649
-
650
-
651
-    /**
652
-     *    get_persistent_admin_notices
653
-     *
654
-     * @access    public
655
-     * @return        void
656
-     */
657
-    public function get_persistent_admin_notices()
658
-    {
659
-        // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
660
-        $args       = array(
661
-            'page'   => EE_Registry::instance()->REQ->is_set('page')
662
-                ? EE_Registry::instance()->REQ->get('page')
663
-                : '',
664
-            'action' => EE_Registry::instance()->REQ->is_set('action')
665
-                ? EE_Registry::instance()->REQ->get('action')
666
-                : '',
667
-        );
668
-        $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
669
-        echo EE_Error::get_persistent_admin_notices($return_url);
670
-    }
671
-
672
-
673
-    /**
674
-     *    dismiss_persistent_admin_notice
675
-     *
676
-     * @access    public
677
-     * @return        void
678
-     */
679
-    public function dismiss_ee_nag_notice_callback()
680
-    {
681
-        EE_Error::dismiss_persistent_admin_notice();
682
-    }
683
-
684
-
685
-    /**
686
-     * @param array $elements
687
-     * @return array
688
-     * @throws \EE_Error
689
-     */
690
-    public function dashboard_glance_items($elements)
691
-    {
692
-        $elements                        = is_array($elements) ? $elements : array($elements);
693
-        $events                          = EEM_Event::instance()->count();
694
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
695
-            array('page' => 'espresso_events'),
696
-            admin_url('admin.php')
697
-        );
698
-        $items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
699
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
700
-        $registrations                   = EEM_Registration::instance()->count(
701
-            array(
702
-                array(
703
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
704
-                ),
705
-            )
706
-        );
707
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
708
-            array('page' => 'espresso_registrations'),
709
-            admin_url('admin.php')
710
-        );
711
-        $items['registrations']['text']  = sprintf(
712
-            _n('%s Registration', '%s Registrations', $registrations),
713
-            number_format_i18n($registrations)
714
-        );
715
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
716
-
717
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
718
-
719
-        foreach ($items as $type => $item_properties) {
720
-            $elements[] = sprintf(
721
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
722
-                $item_properties['url'],
723
-                $item_properties['title'],
724
-                $item_properties['text']
725
-            );
726
-        }
727
-        return $elements;
728
-    }
729
-
730
-
731
-    /**
732
-     *    check_for_invalid_datetime_formats
733
-     *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
734
-     *    their selected format can be parsed by PHP
735
-     *
736
-     * @access    public
737
-     * @param    $value
738
-     * @param    $option
739
-     * @throws EE_Error
740
-     * @return    string
741
-     */
742
-    public function check_for_invalid_datetime_formats($value, $option)
743
-    {
744
-        // check for date_format or time_format
745
-        switch ($option) {
746
-            case 'date_format':
747
-                $date_time_format = $value . ' ' . get_option('time_format');
748
-                break;
749
-            case 'time_format':
750
-                $date_time_format = get_option('date_format') . ' ' . $value;
751
-                break;
752
-            default:
753
-                $date_time_format = false;
754
-        }
755
-        // do we have a date_time format to check ?
756
-        if ($date_time_format) {
757
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
758
-
759
-            if (is_array($error_msg)) {
760
-                $msg = '<p>'
761
-                       . sprintf(
762
-                           esc_html__(
763
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
764
-                               'event_espresso'
765
-                           ),
766
-                           date($date_time_format),
767
-                           $date_time_format
768
-                       )
769
-                       . '</p><p><ul>';
770
-
771
-
772
-                foreach ($error_msg as $error) {
773
-                    $msg .= '<li>' . $error . '</li>';
774
-                }
775
-
776
-                $msg .= '</ul></p><p>'
777
-                        . sprintf(
778
-                            esc_html__(
779
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
780
-                                'event_espresso'
781
-                            ),
782
-                            '<span style="color:#D54E21;">',
783
-                            '</span>'
784
-                        )
785
-                        . '</p>';
786
-
787
-                // trigger WP settings error
788
-                add_settings_error(
789
-                    'date_format',
790
-                    'date_format',
791
-                    $msg
792
-                );
793
-
794
-                // set format to something valid
795
-                switch ($option) {
796
-                    case 'date_format':
797
-                        $value = 'F j, Y';
798
-                        break;
799
-                    case 'time_format':
800
-                        $value = 'g:i a';
801
-                        break;
802
-                }
803
-            }
804
-        }
805
-        return $value;
806
-    }
807
-
808
-
809
-    /**
810
-     *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
811
-     *
812
-     * @access    public
813
-     * @param $content
814
-     * @return    string
815
-     */
816
-    public function its_eSpresso($content)
817
-    {
818
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
819
-    }
820
-
821
-
822
-    /**
823
-     *    espresso_admin_footer
824
-     *
825
-     * @access    public
826
-     * @return    string
827
-     */
828
-    public function espresso_admin_footer()
829
-    {
830
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
831
-    }
832
-
833
-
834
-    /**
835
-     * static method for registering ee admin page.
836
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
837
-     *
838
-     * @since      4.3.0
839
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
840
-     * @see        EE_Register_Admin_Page::register()
841
-     * @param       $page_basename
842
-     * @param       $page_path
843
-     * @param array $config
844
-     * @return void
845
-     * @throws EE_Error
846
-     */
847
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
848
-    {
849
-        EE_Error::doing_it_wrong(
850
-            __METHOD__,
851
-            sprintf(
852
-                esc_html__(
853
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
854
-                    'event_espresso'
855
-                ),
856
-                $page_basename
857
-            ),
858
-            '4.3'
859
-        );
860
-        if (class_exists('EE_Register_Admin_Page')) {
861
-            $config['page_path'] = $page_path;
862
-        }
863
-        EE_Register_Admin_Page::register($page_basename, $config);
864
-    }
865
-
866
-
867
-    /**
868
-     * @deprecated 4.8.41
869
-     * @access     public
870
-     * @param  int      $post_ID
871
-     * @param  \WP_Post $post
872
-     * @return void
873
-     */
874
-    public static function parse_post_content_on_save($post_ID, $post)
875
-    {
876
-        EE_Error::doing_it_wrong(
877
-            __METHOD__,
878
-            esc_html__('Usage is deprecated', 'event_espresso'),
879
-            '4.8.41'
880
-        );
881
-    }
882
-
883
-
884
-    /**
885
-     * @deprecated 4.8.41
886
-     * @access     public
887
-     * @param  $option
888
-     * @param  $old_value
889
-     * @param  $value
890
-     * @return void
891
-     */
892
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
893
-    {
894
-        EE_Error::doing_it_wrong(
895
-            __METHOD__,
896
-            esc_html__('Usage is deprecated', 'event_espresso'),
897
-            '4.8.41'
898
-        );
899
-    }
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns an array of event archive nav items.
424
+	 *
425
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
426
+	 *        method we use for getting the extra nav menu items
427
+	 * @return array
428
+	 */
429
+	private function _get_extra_nav_menu_pages_items()
430
+	{
431
+		$menuitems[] = array(
432
+			'title'       => esc_html__('Event List', 'event_espresso'),
433
+			'url'         => get_post_type_archive_link('espresso_events'),
434
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
435
+		);
436
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
437
+	}
438
+
439
+
440
+	/**
441
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
442
+	 * the properties and converts it to the menu item object.
443
+	 *
444
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
445
+	 * @param $menu_item_values
446
+	 * @return stdClass
447
+	 */
448
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
449
+	{
450
+		$menu_item = new stdClass();
451
+		$keys      = array(
452
+			'ID'               => 0,
453
+			'db_id'            => 0,
454
+			'menu_item_parent' => 0,
455
+			'object_id'        => -1,
456
+			'post_parent'      => 0,
457
+			'type'             => 'custom',
458
+			'object'           => '',
459
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
460
+			'title'            => '',
461
+			'url'              => '',
462
+			'target'           => '',
463
+			'attr_title'       => '',
464
+			'description'      => '',
465
+			'classes'          => array(),
466
+			'xfn'              => '',
467
+		);
468
+
469
+		foreach ($keys as $key => $value) {
470
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
471
+		}
472
+		return $menu_item;
473
+	}
474
+
475
+
476
+	/**
477
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
478
+	 * EE_Admin_Page route is called.
479
+	 *
480
+	 * @return void
481
+	 */
482
+	public function route_admin_request()
483
+	{
484
+	}
485
+
486
+
487
+	/**
488
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
489
+	 *
490
+	 * @return void
491
+	 */
492
+	public function wp_loaded()
493
+	{
494
+	}
495
+
496
+
497
+	/**
498
+	 * admin_init
499
+	 *
500
+	 * @access public
501
+	 * @return void
502
+	 * @throws EE_Error
503
+	 * @throws ReflectionException
504
+	 */
505
+	public function admin_init()
506
+	{
507
+
508
+		/**
509
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
510
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
511
+		 * - check if doing post processing.
512
+		 * - check if doing post processing of one of EE CPTs
513
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
514
+		 */
515
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
516
+			EE_Registry::instance()->load_core('Register_CPTs');
517
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
518
+		}
519
+
520
+
521
+		/**
522
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
523
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
524
+		 * Pages" tab in the EE General Settings Admin page.
525
+		 * This is for user-proofing.
526
+		 */
527
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
528
+	}
529
+
530
+
531
+	/**
532
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
533
+	 *
534
+	 * @param string $output Current output.
535
+	 * @return string
536
+	 */
537
+	public function modify_dropdown_pages($output)
538
+	{
539
+		//get critical pages
540
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
541
+
542
+		//split current output by line break for easier parsing.
543
+		$split_output = explode("\n", $output);
544
+
545
+		//loop through to remove any critical pages from the array.
546
+		foreach ($critical_pages as $page_id) {
547
+			$needle = 'value="' . $page_id . '"';
548
+			foreach ($split_output as $key => $haystack) {
549
+				if (strpos($haystack, $needle) !== false) {
550
+					unset($split_output[$key]);
551
+				}
552
+			}
553
+		}
554
+
555
+		//replace output with the new contents
556
+		return implode("\n", $split_output);
557
+	}
558
+
559
+
560
+	/**
561
+	 * enqueue all admin scripts that need loaded for admin pages
562
+	 *
563
+	 * @access public
564
+	 * @return void
565
+	 */
566
+	public function enqueue_admin_scripts()
567
+	{
568
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
569
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
570
+		// calls.
571
+		wp_enqueue_script(
572
+			'ee-inject-wp',
573
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
574
+			array('jquery'),
575
+			EVENT_ESPRESSO_VERSION,
576
+			true
577
+		);
578
+		// register cookie script for future dependencies
579
+		wp_register_script(
580
+			'jquery-cookie',
581
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
582
+			array('jquery'),
583
+			'2.1',
584
+			true
585
+		);
586
+		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
587
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
588
+		if (apply_filters('FHEE_load_joyride', false)) {
589
+			//joyride style
590
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
591
+			wp_register_style(
592
+				'ee-joyride-css',
593
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
594
+				array('joyride-css'),
595
+				EVENT_ESPRESSO_VERSION
596
+			);
597
+			wp_register_script(
598
+				'joyride-modernizr',
599
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
600
+				array(),
601
+				'2.1',
602
+				true
603
+			);
604
+			//joyride JS
605
+			wp_register_script(
606
+				'jquery-joyride',
607
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
608
+				array('jquery-cookie', 'joyride-modernizr'),
609
+				'2.1',
610
+				true
611
+			);
612
+			// wanna go for a joyride?
613
+			wp_enqueue_style('ee-joyride-css');
614
+			wp_enqueue_script('jquery-joyride');
615
+		}
616
+	}
617
+
618
+
619
+	/**
620
+	 *    display_admin_notices
621
+	 *
622
+	 * @access    public
623
+	 * @return    string
624
+	 */
625
+	public function display_admin_notices()
626
+	{
627
+		//add non-dismissable notice for datetime changes.  Only valid if EE version is greater than 4.9.46.p and the
628
+		// site does not have a timezone_string set.
629
+		if (EE_Register_Addon::_meets_min_core_version_requirement(
630
+				'4.9.46.p'
631
+			)
632
+			&& ! get_option('timezone_string')
633
+		) {
634
+			EE_Error::add_attention(
635
+				sprintf(
636
+					esc_html__(
637
+						'%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website.  Read more about it %3$shere%4$s.',
638
+						'event_espresso'
639
+					),
640
+					'<strong>',
641
+					'</strong>',
642
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
643
+					'</a>'
644
+				)
645
+			);
646
+		}
647
+		echo EE_Error::get_notices();
648
+	}
649
+
650
+
651
+	/**
652
+	 *    get_persistent_admin_notices
653
+	 *
654
+	 * @access    public
655
+	 * @return        void
656
+	 */
657
+	public function get_persistent_admin_notices()
658
+	{
659
+		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
660
+		$args       = array(
661
+			'page'   => EE_Registry::instance()->REQ->is_set('page')
662
+				? EE_Registry::instance()->REQ->get('page')
663
+				: '',
664
+			'action' => EE_Registry::instance()->REQ->is_set('action')
665
+				? EE_Registry::instance()->REQ->get('action')
666
+				: '',
667
+		);
668
+		$return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
669
+		echo EE_Error::get_persistent_admin_notices($return_url);
670
+	}
671
+
672
+
673
+	/**
674
+	 *    dismiss_persistent_admin_notice
675
+	 *
676
+	 * @access    public
677
+	 * @return        void
678
+	 */
679
+	public function dismiss_ee_nag_notice_callback()
680
+	{
681
+		EE_Error::dismiss_persistent_admin_notice();
682
+	}
683
+
684
+
685
+	/**
686
+	 * @param array $elements
687
+	 * @return array
688
+	 * @throws \EE_Error
689
+	 */
690
+	public function dashboard_glance_items($elements)
691
+	{
692
+		$elements                        = is_array($elements) ? $elements : array($elements);
693
+		$events                          = EEM_Event::instance()->count();
694
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
695
+			array('page' => 'espresso_events'),
696
+			admin_url('admin.php')
697
+		);
698
+		$items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
699
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
700
+		$registrations                   = EEM_Registration::instance()->count(
701
+			array(
702
+				array(
703
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
704
+				),
705
+			)
706
+		);
707
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
708
+			array('page' => 'espresso_registrations'),
709
+			admin_url('admin.php')
710
+		);
711
+		$items['registrations']['text']  = sprintf(
712
+			_n('%s Registration', '%s Registrations', $registrations),
713
+			number_format_i18n($registrations)
714
+		);
715
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
716
+
717
+		$items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
718
+
719
+		foreach ($items as $type => $item_properties) {
720
+			$elements[] = sprintf(
721
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
722
+				$item_properties['url'],
723
+				$item_properties['title'],
724
+				$item_properties['text']
725
+			);
726
+		}
727
+		return $elements;
728
+	}
729
+
730
+
731
+	/**
732
+	 *    check_for_invalid_datetime_formats
733
+	 *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
734
+	 *    their selected format can be parsed by PHP
735
+	 *
736
+	 * @access    public
737
+	 * @param    $value
738
+	 * @param    $option
739
+	 * @throws EE_Error
740
+	 * @return    string
741
+	 */
742
+	public function check_for_invalid_datetime_formats($value, $option)
743
+	{
744
+		// check for date_format or time_format
745
+		switch ($option) {
746
+			case 'date_format':
747
+				$date_time_format = $value . ' ' . get_option('time_format');
748
+				break;
749
+			case 'time_format':
750
+				$date_time_format = get_option('date_format') . ' ' . $value;
751
+				break;
752
+			default:
753
+				$date_time_format = false;
754
+		}
755
+		// do we have a date_time format to check ?
756
+		if ($date_time_format) {
757
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
758
+
759
+			if (is_array($error_msg)) {
760
+				$msg = '<p>'
761
+					   . sprintf(
762
+						   esc_html__(
763
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
764
+							   'event_espresso'
765
+						   ),
766
+						   date($date_time_format),
767
+						   $date_time_format
768
+					   )
769
+					   . '</p><p><ul>';
770
+
771
+
772
+				foreach ($error_msg as $error) {
773
+					$msg .= '<li>' . $error . '</li>';
774
+				}
775
+
776
+				$msg .= '</ul></p><p>'
777
+						. sprintf(
778
+							esc_html__(
779
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
780
+								'event_espresso'
781
+							),
782
+							'<span style="color:#D54E21;">',
783
+							'</span>'
784
+						)
785
+						. '</p>';
786
+
787
+				// trigger WP settings error
788
+				add_settings_error(
789
+					'date_format',
790
+					'date_format',
791
+					$msg
792
+				);
793
+
794
+				// set format to something valid
795
+				switch ($option) {
796
+					case 'date_format':
797
+						$value = 'F j, Y';
798
+						break;
799
+					case 'time_format':
800
+						$value = 'g:i a';
801
+						break;
802
+				}
803
+			}
804
+		}
805
+		return $value;
806
+	}
807
+
808
+
809
+	/**
810
+	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
811
+	 *
812
+	 * @access    public
813
+	 * @param $content
814
+	 * @return    string
815
+	 */
816
+	public function its_eSpresso($content)
817
+	{
818
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
819
+	}
820
+
821
+
822
+	/**
823
+	 *    espresso_admin_footer
824
+	 *
825
+	 * @access    public
826
+	 * @return    string
827
+	 */
828
+	public function espresso_admin_footer()
829
+	{
830
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
831
+	}
832
+
833
+
834
+	/**
835
+	 * static method for registering ee admin page.
836
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
837
+	 *
838
+	 * @since      4.3.0
839
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
840
+	 * @see        EE_Register_Admin_Page::register()
841
+	 * @param       $page_basename
842
+	 * @param       $page_path
843
+	 * @param array $config
844
+	 * @return void
845
+	 * @throws EE_Error
846
+	 */
847
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
848
+	{
849
+		EE_Error::doing_it_wrong(
850
+			__METHOD__,
851
+			sprintf(
852
+				esc_html__(
853
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
854
+					'event_espresso'
855
+				),
856
+				$page_basename
857
+			),
858
+			'4.3'
859
+		);
860
+		if (class_exists('EE_Register_Admin_Page')) {
861
+			$config['page_path'] = $page_path;
862
+		}
863
+		EE_Register_Admin_Page::register($page_basename, $config);
864
+	}
865
+
866
+
867
+	/**
868
+	 * @deprecated 4.8.41
869
+	 * @access     public
870
+	 * @param  int      $post_ID
871
+	 * @param  \WP_Post $post
872
+	 * @return void
873
+	 */
874
+	public static function parse_post_content_on_save($post_ID, $post)
875
+	{
876
+		EE_Error::doing_it_wrong(
877
+			__METHOD__,
878
+			esc_html__('Usage is deprecated', 'event_espresso'),
879
+			'4.8.41'
880
+		);
881
+	}
882
+
883
+
884
+	/**
885
+	 * @deprecated 4.8.41
886
+	 * @access     public
887
+	 * @param  $option
888
+	 * @param  $old_value
889
+	 * @param  $value
890
+	 * @return void
891
+	 */
892
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
893
+	{
894
+		EE_Error::doing_it_wrong(
895
+			__METHOD__,
896
+			esc_html__('Usage is deprecated', 'event_espresso'),
897
+			'4.8.41'
898
+		);
899
+	}
900 900
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -157,7 +157,7 @@
 block discarded – undo
157 157
     /**
158 158
      * This retrieves the EE_Venue from the available data object.
159 159
      *
160
-     * @return EE_Venue|null
160
+     * @return EE_Base_Class|null
161 161
      */
162 162
     private function _get_venue() {
163 163
 
Please login to merge, or discard this patch.
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -16,288 +16,288 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Will hold the EE_Event if available
21
-     *
22
-     * @var EE_Event
23
-     */
24
-    protected $_event;
25
-
26
-    /**
27
-     * Will hold the EE_Venue if available
28
-     *
29
-     * @var EE_Venue
30
-     */
31
-    protected $_venue;
32
-
33
-
34
-    /**
35
-     * Initialize properties
36
-     */
37
-    protected function _init_props()
38
-    {
39
-        $this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
40
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
41
-        $this->_shortcodes = array(
42
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
43
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
44
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
45
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
46
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
47
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
48
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
49
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
50
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
51
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
52
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
53
-                'This just outputs the venue address in a semantic address format.',
54
-                'event_espresso'
55
-            ),
56
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
57
-            '[VENUE_META_*]'            => esc_html__(
58
-                'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', 
59
-                'event_espresso'
60
-            ),
61
-            '[GOOGLE_MAP_URL]'          => esc_html__(
62
-                'URL for the google map associated with the venue.', 
63
-                'event_espresso'
64
-            ),
65
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
66
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
67
-        );
68
-    }
69
-
70
-
71
-    /**
72
-     * Parse incoming shortcode
73
-     * @param string $shortcode
74
-     * @return string
75
-     */
76
-    protected function _parser($shortcode)
77
-    {
78
-        $this->_venue = $this->_get_venue();
79
-        //If there is no venue object by now then get out.
80
-        if ( ! $this->_venue instanceof EE_Venue )
81
-            return '';
82
-
83
-        switch ($shortcode) {
84
-            case '[VENUE_TITLE]':
85
-                return $this->_venue('title');
86
-                break;
87
-
88
-            case '[VENUE_DESCRIPTION]':
89
-                return $this->_venue('description');
90
-                break;
91
-
92
-            case '[VENUE_URL]':
93
-                return $this->_venue('url');
94
-                break;
95
-
96
-            case '[VENUE_IMAGE]':
97
-                return $this->_venue('image');
98
-                break;
99
-
100
-            case '[VENUE_PHONE]':
101
-                return $this->_venue('phone');
102
-                break;
103
-
104
-            case '[VENUE_ADDRESS]':
105
-                return $this->_venue('address');
106
-                break;
107
-
108
-            case '[VENUE_ADDRESS2]':
109
-                return $this->_venue('address2');
110
-                break;
111
-
112
-            case '[VENUE_CITY]':
113
-                return $this->_venue('city');
114
-                break;
115
-
116
-            case '[VENUE_COUNTRY]':
117
-                return $this->_venue('country');
118
-                break;
119
-
120
-            case '[VENUE_STATE]':
121
-                return $this->_venue('state');
122
-                break;
123
-
124
-            case '[VENUE_ZIP]':
125
-                return $this->_venue('zip');
126
-                break;
127
-
128
-            case '[VENUE_FORMATTED_ADDRESS]':
129
-                return $this->_venue('formatted_address');
130
-                break;
131
-
132
-            case '[GOOGLE_MAP_URL]':
133
-                return $this->_venue('gmap_url');
134
-                break;
135
-
136
-            case '[GOOGLE_MAP_LINK]':
137
-                return $this->_venue('gmap_link');
138
-                break;
139
-
140
-            case '[GOOGLE_MAP_IMAGE]':
141
-                return $this->_venue('gmap_link_img');
142
-                break;
143
-
144
-        }
145
-
146
-        if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) {
147
-            $shortcode = str_replace( '[VENUE_META_*', '', $shortcode );
148
-            $shortcode = trim( str_replace( ']', '', $shortcode ) );
149
-
150
-            //pull the meta value from the venue post
151
-            $venue_meta = $this->_venue->get_post_meta( $shortcode, true );
152
-
153
-            return ! empty( $venue_meta ) ? $venue_meta : '';
154
-
155
-        }
156
-    }
157
-    /**
158
-     * This retrieves the EE_Venue from the available data object.
159
-     *
160
-     * @return EE_Venue|null
161
-     */
162
-    private function _get_venue() {
163
-
164
-        //we need the EE_Event object to get the venue.
165
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
166
-
167
-        //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
168
-        if (empty($this->_event)) {
169
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
170
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
171
-
172
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null;
173
-
174
-            //if still empty do we have a ticket data item?
175
-            $this->_event = empty($this->_event)
176
-                            && $this->_data instanceof EE_Ticket
177
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
178
-                ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
179
-                : $this->_event;
180
-
181
-            //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that.
182
-            $event        = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array();
183
-            $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event;
184
-        }
185
-
186
-        //If we have an event object use it to pull the venue.
187
-        if ($this->_event instanceof EE_Event) {
188
-            return $this->_event->get_first_related('Venue');
189
-        } 
190
-
191
-        return null;
192
-    }
193
-
194
-    /**
195
-     * This retrieves the specified venue information
196
-     *
197
-     * @param string $field  What Venue field to retrieve
198
-     * @return string What was retrieved!
199
-     * @throws EE_Error
200
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
201
-     */
202
-    private function _venue($field)
203
-    {
204
-
205
-        if (empty($this->_venue)) {
206
-            return '';
207
-        } //no venue so get out.
208
-
209
-        switch ($field) {
210
-            case 'title':
211
-                return $this->_venue->get('VNU_name');
212
-                break;
213
-
214
-            case 'description':
215
-                return $this->_venue->get('VNU_desc');
216
-                break;
217
-
218
-            case 'url':
219
-                $url = $this->_venue->get('VNU_url');
220
-                return empty($url) ? $this->_venue->get_permalink() : $url;
221
-                break;
222
-
223
-            case 'image':
224
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
225
-                       . '" alt="' . sprintf(
226
-                           esc_attr__('%s Feature Image', 'event_espresso'),
227
-                           $this->_venue->get('VNU_name')
228
-                       ) . '" />';
229
-                break;
230
-
231
-            case 'phone':
232
-                return $this->_venue->get('VNU_phone');
233
-                break;
234
-
235
-            case 'address':
236
-                return $this->_venue->get('VNU_address');
237
-                break;
238
-
239
-            case 'address2':
240
-                return $this->_venue->get('VNU_address2');
241
-                break;
242
-
243
-            case 'city':
244
-                return $this->_venue->get('VNU_city');
245
-                break;
246
-
247
-            case 'state':
248
-                $state = $this->_venue->state_obj();
249
-                return is_object($state) ? $state->get('STA_name') : '';
250
-                break;
251
-
252
-            case 'country':
253
-                $country = $this->_venue->country_obj();
254
-                return is_object($country) ? $country->get('CNT_name') : '';
255
-                break;
256
-
257
-            case 'zip':
258
-                return $this->_venue->get('VNU_zip');
259
-                break;
260
-
261
-            case 'formatted_address':
262
-                return EEH_Address::format($this->_venue);
263
-                break;
264
-
265
-            case 'gmap_link':
266
-            case 'gmap_url':
267
-            case 'gmap_link_img':
268
-                $atts = $this->get_map_attributes($this->_venue, $field);
269
-                return EEH_Maps::google_map_link($atts);
270
-                break;
271
-        }
272
-        return '';
273
-    }
274
-
275
-
276
-    /**
277
-     * Generates the attributes for retrieving a google_map artifact.
278
-     * @param EE_Venue $venue
279
-     * @param string   $field
280
-     * @return array
281
-     * @throws EE_Error
282
-     */
283
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
284
-    {
285
-        $state   = $venue->state_obj();
286
-        $country = $venue->country_obj();
287
-        $atts    = array(
288
-            'id'      => $venue->ID(),
289
-            'address' => $venue->get('VNU_address'),
290
-            'city'    => $venue->get('VNU_city'),
291
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
292
-            'zip'     => $venue->get('VNU_zip'),
293
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
294
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
295
-            'map_w'   => 200,
296
-            'map_h'   => 200,
297
-        );
298
-        if ($field === 'gmap_url') {
299
-            $atts['type'] = 'url_only';
300
-        }
301
-        return $atts;
302
-    }
19
+	/**
20
+	 * Will hold the EE_Event if available
21
+	 *
22
+	 * @var EE_Event
23
+	 */
24
+	protected $_event;
25
+
26
+	/**
27
+	 * Will hold the EE_Venue if available
28
+	 *
29
+	 * @var EE_Venue
30
+	 */
31
+	protected $_venue;
32
+
33
+
34
+	/**
35
+	 * Initialize properties
36
+	 */
37
+	protected function _init_props()
38
+	{
39
+		$this->label       = esc_html__('Venue Shortcodes', 'event_espresso');
40
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
41
+		$this->_shortcodes = array(
42
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
43
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
44
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
45
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
46
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
47
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
48
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
49
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
50
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
51
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
52
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
53
+				'This just outputs the venue address in a semantic address format.',
54
+				'event_espresso'
55
+			),
56
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
57
+			'[VENUE_META_*]'            => esc_html__(
58
+				'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', 
59
+				'event_espresso'
60
+			),
61
+			'[GOOGLE_MAP_URL]'          => esc_html__(
62
+				'URL for the google map associated with the venue.', 
63
+				'event_espresso'
64
+			),
65
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
66
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
67
+		);
68
+	}
69
+
70
+
71
+	/**
72
+	 * Parse incoming shortcode
73
+	 * @param string $shortcode
74
+	 * @return string
75
+	 */
76
+	protected function _parser($shortcode)
77
+	{
78
+		$this->_venue = $this->_get_venue();
79
+		//If there is no venue object by now then get out.
80
+		if ( ! $this->_venue instanceof EE_Venue )
81
+			return '';
82
+
83
+		switch ($shortcode) {
84
+			case '[VENUE_TITLE]':
85
+				return $this->_venue('title');
86
+				break;
87
+
88
+			case '[VENUE_DESCRIPTION]':
89
+				return $this->_venue('description');
90
+				break;
91
+
92
+			case '[VENUE_URL]':
93
+				return $this->_venue('url');
94
+				break;
95
+
96
+			case '[VENUE_IMAGE]':
97
+				return $this->_venue('image');
98
+				break;
99
+
100
+			case '[VENUE_PHONE]':
101
+				return $this->_venue('phone');
102
+				break;
103
+
104
+			case '[VENUE_ADDRESS]':
105
+				return $this->_venue('address');
106
+				break;
107
+
108
+			case '[VENUE_ADDRESS2]':
109
+				return $this->_venue('address2');
110
+				break;
111
+
112
+			case '[VENUE_CITY]':
113
+				return $this->_venue('city');
114
+				break;
115
+
116
+			case '[VENUE_COUNTRY]':
117
+				return $this->_venue('country');
118
+				break;
119
+
120
+			case '[VENUE_STATE]':
121
+				return $this->_venue('state');
122
+				break;
123
+
124
+			case '[VENUE_ZIP]':
125
+				return $this->_venue('zip');
126
+				break;
127
+
128
+			case '[VENUE_FORMATTED_ADDRESS]':
129
+				return $this->_venue('formatted_address');
130
+				break;
131
+
132
+			case '[GOOGLE_MAP_URL]':
133
+				return $this->_venue('gmap_url');
134
+				break;
135
+
136
+			case '[GOOGLE_MAP_LINK]':
137
+				return $this->_venue('gmap_link');
138
+				break;
139
+
140
+			case '[GOOGLE_MAP_IMAGE]':
141
+				return $this->_venue('gmap_link_img');
142
+				break;
143
+
144
+		}
145
+
146
+		if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) {
147
+			$shortcode = str_replace( '[VENUE_META_*', '', $shortcode );
148
+			$shortcode = trim( str_replace( ']', '', $shortcode ) );
149
+
150
+			//pull the meta value from the venue post
151
+			$venue_meta = $this->_venue->get_post_meta( $shortcode, true );
152
+
153
+			return ! empty( $venue_meta ) ? $venue_meta : '';
154
+
155
+		}
156
+	}
157
+	/**
158
+	 * This retrieves the EE_Venue from the available data object.
159
+	 *
160
+	 * @return EE_Venue|null
161
+	 */
162
+	private function _get_venue() {
163
+
164
+		//we need the EE_Event object to get the venue.
165
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
166
+
167
+		//if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
168
+		if (empty($this->_event)) {
169
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
170
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
171
+
172
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null;
173
+
174
+			//if still empty do we have a ticket data item?
175
+			$this->_event = empty($this->_event)
176
+							&& $this->_data instanceof EE_Ticket
177
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
178
+				? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
179
+				: $this->_event;
180
+
181
+			//if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that.
182
+			$event        = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array();
183
+			$this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event;
184
+		}
185
+
186
+		//If we have an event object use it to pull the venue.
187
+		if ($this->_event instanceof EE_Event) {
188
+			return $this->_event->get_first_related('Venue');
189
+		} 
190
+
191
+		return null;
192
+	}
193
+
194
+	/**
195
+	 * This retrieves the specified venue information
196
+	 *
197
+	 * @param string $field  What Venue field to retrieve
198
+	 * @return string What was retrieved!
199
+	 * @throws EE_Error
200
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
201
+	 */
202
+	private function _venue($field)
203
+	{
204
+
205
+		if (empty($this->_venue)) {
206
+			return '';
207
+		} //no venue so get out.
208
+
209
+		switch ($field) {
210
+			case 'title':
211
+				return $this->_venue->get('VNU_name');
212
+				break;
213
+
214
+			case 'description':
215
+				return $this->_venue->get('VNU_desc');
216
+				break;
217
+
218
+			case 'url':
219
+				$url = $this->_venue->get('VNU_url');
220
+				return empty($url) ? $this->_venue->get_permalink() : $url;
221
+				break;
222
+
223
+			case 'image':
224
+				return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
225
+					   . '" alt="' . sprintf(
226
+						   esc_attr__('%s Feature Image', 'event_espresso'),
227
+						   $this->_venue->get('VNU_name')
228
+					   ) . '" />';
229
+				break;
230
+
231
+			case 'phone':
232
+				return $this->_venue->get('VNU_phone');
233
+				break;
234
+
235
+			case 'address':
236
+				return $this->_venue->get('VNU_address');
237
+				break;
238
+
239
+			case 'address2':
240
+				return $this->_venue->get('VNU_address2');
241
+				break;
242
+
243
+			case 'city':
244
+				return $this->_venue->get('VNU_city');
245
+				break;
246
+
247
+			case 'state':
248
+				$state = $this->_venue->state_obj();
249
+				return is_object($state) ? $state->get('STA_name') : '';
250
+				break;
251
+
252
+			case 'country':
253
+				$country = $this->_venue->country_obj();
254
+				return is_object($country) ? $country->get('CNT_name') : '';
255
+				break;
256
+
257
+			case 'zip':
258
+				return $this->_venue->get('VNU_zip');
259
+				break;
260
+
261
+			case 'formatted_address':
262
+				return EEH_Address::format($this->_venue);
263
+				break;
264
+
265
+			case 'gmap_link':
266
+			case 'gmap_url':
267
+			case 'gmap_link_img':
268
+				$atts = $this->get_map_attributes($this->_venue, $field);
269
+				return EEH_Maps::google_map_link($atts);
270
+				break;
271
+		}
272
+		return '';
273
+	}
274
+
275
+
276
+	/**
277
+	 * Generates the attributes for retrieving a google_map artifact.
278
+	 * @param EE_Venue $venue
279
+	 * @param string   $field
280
+	 * @return array
281
+	 * @throws EE_Error
282
+	 */
283
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
284
+	{
285
+		$state   = $venue->state_obj();
286
+		$country = $venue->country_obj();
287
+		$atts    = array(
288
+			'id'      => $venue->ID(),
289
+			'address' => $venue->get('VNU_address'),
290
+			'city'    => $venue->get('VNU_city'),
291
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
292
+			'zip'     => $venue->get('VNU_zip'),
293
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
294
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
295
+			'map_w'   => 200,
296
+			'map_h'   => 200,
297
+		);
298
+		if ($field === 'gmap_url') {
299
+			$atts['type'] = 'url_only';
300
+		}
301
+		return $atts;
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $this->_venue = $this->_get_venue();
79 79
         //If there is no venue object by now then get out.
80
-        if ( ! $this->_venue instanceof EE_Venue )
80
+        if ( ! $this->_venue instanceof EE_Venue)
81 81
             return '';
82 82
 
83 83
         switch ($shortcode) {
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 
144 144
         }
145 145
 
146
-        if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) {
147
-            $shortcode = str_replace( '[VENUE_META_*', '', $shortcode );
148
-            $shortcode = trim( str_replace( ']', '', $shortcode ) );
146
+        if (strpos($shortcode, '[VENUE_META_*') !== false) {
147
+            $shortcode = str_replace('[VENUE_META_*', '', $shortcode);
148
+            $shortcode = trim(str_replace(']', '', $shortcode));
149 149
 
150 150
             //pull the meta value from the venue post
151
-            $venue_meta = $this->_venue->get_post_meta( $shortcode, true );
151
+            $venue_meta = $this->_venue->get_post_meta($shortcode, true);
152 152
 
153
-            return ! empty( $venue_meta ) ? $venue_meta : '';
153
+            return ! empty($venue_meta) ? $venue_meta : '';
154 154
 
155 155
         }
156 156
     }
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
                 break;
222 222
 
223 223
             case 'image':
224
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
225
-                       . '" alt="' . sprintf(
224
+                return '<img src="'.$this->_venue->feature_image_url(array(200, 200,))
225
+                       . '" alt="'.sprintf(
226 226
                            esc_attr__('%s Feature Image', 'event_espresso'),
227 227
                            $this->_venue->get('VNU_name')
228
-                       ) . '" />';
228
+                       ).'" />';
229 229
                 break;
230 230
 
231 231
             case 'phone':
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,8 +77,9 @@
 block discarded – undo
77 77
     {
78 78
         $this->_venue = $this->_get_venue();
79 79
         //If there is no venue object by now then get out.
80
-        if ( ! $this->_venue instanceof EE_Venue )
81
-            return '';
80
+        if ( ! $this->_venue instanceof EE_Venue ) {
81
+                    return '';
82
+        }
82 83
 
83 84
         switch ($shortcode) {
84 85
             case '[VENUE_TITLE]':
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.
core/db_models/EEM_WP_User.model.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\services\orm\ModelFieldFactory;
4 4
 
5 5
 if (! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('No direct script access allowed');
6
+	exit('No direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -19,128 +19,128 @@  discard block
 block discarded – undo
19 19
 class EEM_WP_User extends EEM_Base
20 20
 {
21 21
 
22
-    /**
23
-     * private instance of the EEM_WP_User object
24
-     *
25
-     * @type EEM_WP_User
26
-     */
27
-    protected static $_instance;
28
-
29
-
30
-
31
-    /**
32
-     *    constructor
33
-     *
34
-     * @param null              $timezone
35
-     * @param ModelFieldFactory $model_field_factory
36
-     * @throws EE_Error
37
-     * @throws InvalidArgumentException
38
-     */
39
-    protected function __construct($timezone = null, ModelFieldFactory $model_field_factory)
40
-    {
41
-        $this->singular_item = __('WP_User', 'event_espresso');
42
-        $this->plural_item = __('WP_Users', 'event_espresso');
43
-        global $wpdb;
44
-        $this->_tables = array(
45
-            'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
46
-        );
47
-        $this->_fields = array(
48
-            'WP_User' => array(
49
-                'ID'                  => $model_field_factory->createPrimaryKeyIntField(
50
-                    'ID',
51
-                    __('WP_User ID', 'event_espresso')
52
-                ),
53
-                'user_login'          => $model_field_factory->createPlainTextField(
54
-                    'user_login',
55
-                    __('User Login', 'event_espresso'),
56
-                    false
57
-                ),
58
-                'user_pass'           => $model_field_factory->createPlainTextField(
59
-                    'user_pass',
60
-                    __('User Password', 'event_espresso'),
61
-                    false
62
-                ),
63
-                'user_nicename'       => $model_field_factory->createPlainTextField(
64
-                    'user_nicename',
65
-                    __(' User Nice Name', 'event_espresso'),
66
-                    false
67
-                ),
68
-                'user_email'          => $model_field_factory->createEmailField(
69
-                    'user_email',
70
-                    __('User Email', 'event_espresso'),
71
-                    false,
72
-                    null
73
-                ),
74
-                'user_registered'     => $model_field_factory->createDatetimeField(
75
-                    'user_registered',
76
-                    __('Date User Registered', 'event_espresso'),
77
-                    $timezone
78
-                ),
79
-                'user_activation_key' => $model_field_factory->createPlainTextField(
80
-                    'user_activation_key',
81
-                    __('User Activation Key', 'event_espresso'),
82
-                    false
83
-                ),
84
-                'user_status'         => $model_field_factory->createIntegerField(
85
-                    'user_status',
86
-                    __('User Status', 'event_espresso')
87
-                ),
88
-                'display_name'        => $model_field_factory->createPlainTextField(
89
-                    'display_name',
90
-                    __('Display Name', 'event_espresso'),
91
-                    false
92
-                ),
93
-            ),
94
-        );
95
-        $this->_model_relations = array(
96
-            'Attendee'       => new EE_Has_Many_Relation(),
97
-            // all models are related to the change log
98
-            // 'Change_Log'     => new EE_Has_Many_Relation(),
99
-            'Event'          => new EE_Has_Many_Relation(),
100
-            'Payment_Method' => new EE_Has_Many_Relation(),
101
-            'Price'          => new EE_Has_Many_Relation(),
102
-            'Price_Type'     => new EE_Has_Many_Relation(),
103
-            'Question'       => new EE_Has_Many_Relation(),
104
-            'Question_Group' => new EE_Has_Many_Relation(),
105
-            'Ticket'         => new EE_Has_Many_Relation(),
106
-            'Venue'          => new EE_Has_Many_Relation(),
107
-            'Message'        => new EE_Has_Many_Relation(),
108
-        );
109
-        $this->_wp_core_model = true;
110
-        $this->_caps_slug = 'users';
111
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
112
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
113
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
114
-            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
115
-        }
116
-        //@todo: account for create_users controls whether they can create users at all
117
-        parent::__construct($timezone);
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * We don't need a foreign key to the WP_User model, we just need its primary key
124
-     *
125
-     * @return string
126
-     * @throws EE_Error
127
-     */
128
-    public function wp_user_field_name()
129
-    {
130
-        return $this->primary_key_name();
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * This WP_User model IS owned, even though it doesn't have a foreign key to itself
137
-     *
138
-     * @return boolean
139
-     */
140
-    public function is_owned()
141
-    {
142
-        return true;
143
-    }
22
+	/**
23
+	 * private instance of the EEM_WP_User object
24
+	 *
25
+	 * @type EEM_WP_User
26
+	 */
27
+	protected static $_instance;
28
+
29
+
30
+
31
+	/**
32
+	 *    constructor
33
+	 *
34
+	 * @param null              $timezone
35
+	 * @param ModelFieldFactory $model_field_factory
36
+	 * @throws EE_Error
37
+	 * @throws InvalidArgumentException
38
+	 */
39
+	protected function __construct($timezone = null, ModelFieldFactory $model_field_factory)
40
+	{
41
+		$this->singular_item = __('WP_User', 'event_espresso');
42
+		$this->plural_item = __('WP_Users', 'event_espresso');
43
+		global $wpdb;
44
+		$this->_tables = array(
45
+			'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
46
+		);
47
+		$this->_fields = array(
48
+			'WP_User' => array(
49
+				'ID'                  => $model_field_factory->createPrimaryKeyIntField(
50
+					'ID',
51
+					__('WP_User ID', 'event_espresso')
52
+				),
53
+				'user_login'          => $model_field_factory->createPlainTextField(
54
+					'user_login',
55
+					__('User Login', 'event_espresso'),
56
+					false
57
+				),
58
+				'user_pass'           => $model_field_factory->createPlainTextField(
59
+					'user_pass',
60
+					__('User Password', 'event_espresso'),
61
+					false
62
+				),
63
+				'user_nicename'       => $model_field_factory->createPlainTextField(
64
+					'user_nicename',
65
+					__(' User Nice Name', 'event_espresso'),
66
+					false
67
+				),
68
+				'user_email'          => $model_field_factory->createEmailField(
69
+					'user_email',
70
+					__('User Email', 'event_espresso'),
71
+					false,
72
+					null
73
+				),
74
+				'user_registered'     => $model_field_factory->createDatetimeField(
75
+					'user_registered',
76
+					__('Date User Registered', 'event_espresso'),
77
+					$timezone
78
+				),
79
+				'user_activation_key' => $model_field_factory->createPlainTextField(
80
+					'user_activation_key',
81
+					__('User Activation Key', 'event_espresso'),
82
+					false
83
+				),
84
+				'user_status'         => $model_field_factory->createIntegerField(
85
+					'user_status',
86
+					__('User Status', 'event_espresso')
87
+				),
88
+				'display_name'        => $model_field_factory->createPlainTextField(
89
+					'display_name',
90
+					__('Display Name', 'event_espresso'),
91
+					false
92
+				),
93
+			),
94
+		);
95
+		$this->_model_relations = array(
96
+			'Attendee'       => new EE_Has_Many_Relation(),
97
+			// all models are related to the change log
98
+			// 'Change_Log'     => new EE_Has_Many_Relation(),
99
+			'Event'          => new EE_Has_Many_Relation(),
100
+			'Payment_Method' => new EE_Has_Many_Relation(),
101
+			'Price'          => new EE_Has_Many_Relation(),
102
+			'Price_Type'     => new EE_Has_Many_Relation(),
103
+			'Question'       => new EE_Has_Many_Relation(),
104
+			'Question_Group' => new EE_Has_Many_Relation(),
105
+			'Ticket'         => new EE_Has_Many_Relation(),
106
+			'Venue'          => new EE_Has_Many_Relation(),
107
+			'Message'        => new EE_Has_Many_Relation(),
108
+		);
109
+		$this->_wp_core_model = true;
110
+		$this->_caps_slug = 'users';
111
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
112
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
113
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
114
+			$this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
115
+		}
116
+		//@todo: account for create_users controls whether they can create users at all
117
+		parent::__construct($timezone);
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * We don't need a foreign key to the WP_User model, we just need its primary key
124
+	 *
125
+	 * @return string
126
+	 * @throws EE_Error
127
+	 */
128
+	public function wp_user_field_name()
129
+	{
130
+		return $this->primary_key_name();
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * This WP_User model IS owned, even though it doesn't have a foreign key to itself
137
+	 *
138
+	 * @return boolean
139
+	 */
140
+	public function is_owned()
141
+	{
142
+		return true;
143
+	}
144 144
 
145 145
 
146 146
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 use EventEspresso\core\services\orm\ModelFieldFactory;
4 4
 
5
-if (! defined('EVENT_ESPRESSO_VERSION')) {
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6 6
     exit('No direct script access allowed');
7 7
 }
8 8
 
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 2 patches
Indentation   +642 added lines, -642 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
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
 
7 7
 
@@ -17,632 +17,632 @@  discard block
 block discarded – undo
17 17
 class EEH_Debug_Tools
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EEH_Autoloader object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $_memory_usage_points = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EEH_Debug_Tools
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * private class constructor
53
-     */
54
-    private function __construct()
55
-    {
56
-        // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
59
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
-            // so we've moved it to our test folder so that it is not included with production releases
62
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
-        }
65
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
-        //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
-        // }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo $priority;
148
-                foreach ($function as $name => $properties) {
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[$hook_name])) {
168
-            $filters[$hook_name] = array();
169
-            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
-                $filters[$hook_name][$priority] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[$hook_name][$priority][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            __(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__, __FUNCTION__, __LINE__
214
-                    );
215
-                }
216
-            } else {
217
-                // old school attempt
218
-                file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
-                    $activation_errors
221
-                );
222
-            }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
-            update_option('ee_plugin_activation_errors', $activation_errors);
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
-     * or we want to make sure they use something the right way.
234
-     *
235
-     * @access public
236
-     * @param string $function      The function that was called
237
-     * @param string $message       A message explaining what has been done incorrectly
238
-     * @param string $version       The version of Event Espresso where the error was added
239
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
-     *                              for a deprecated function. This allows deprecation to occur during one version,
241
-     *                              but not have any notices appear until a later version. This allows developers
242
-     *                              extra time to update their code before notices appear.
243
-     * @param int    $error_type
244
-     * @uses   trigger_error()
245
-     */
246
-    public function doing_it_wrong(
247
-        $function,
248
-        $message,
249
-        $version,
250
-        $applies_when = '',
251
-        $error_type = null
252
-    ) {
253
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
-        // because we swapped the parameter order around for the last two params,
256
-        // let's verify that some third party isn't still passing an error type value for the third param
257
-        if (is_int($applies_when)) {
258
-            $error_type = $applies_when;
259
-            $applies_when = espresso_version();
260
-        }
261
-        // if not displaying notices yet, then just leave
262
-        if (version_compare(espresso_version(), $applies_when, '<')) {
263
-            return;
264
-        }
265
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
-        $version = $version === null
267
-            ? ''
268
-            : sprintf(
269
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
-                $version
271
-            );
272
-        $error_message = sprintf(
273
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
-            $function,
275
-            '<strong>',
276
-            '</strong>',
277
-            $message,
278
-            $version
279
-        );
280
-        // don't trigger error if doing ajax,
281
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
-        if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
284
-                    'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
-                    'event_espresso'
286
-                );
287
-            $error_message .= '<ul><li>';
288
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
-            $error_message .= '</ul>';
290
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
-            //now we set this on the transient so it shows up on the next request.
292
-            EE_Error::get_notices(false, true);
293
-        } else {
294
-            trigger_error($error_message, $error_type);
295
-        }
296
-    }
297
-
298
-
299
-
300
-
301
-    /**
302
-     * Logger helpers
303
-     */
304
-    /**
305
-     * debug
306
-     *
307
-     * @param string $class
308
-     * @param string $func
309
-     * @param string $line
310
-     * @param array  $info
311
-     * @param bool   $display_request
312
-     * @param string $debug_index
313
-     * @param string $debug_key
314
-     * @throws EE_Error
315
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
-     */
317
-    public static function log(
318
-        $class = '',
319
-        $func = '',
320
-        $line = '',
321
-        $info = array(),
322
-        $display_request = false,
323
-        $debug_index = '',
324
-        $debug_key = 'EE_DEBUG_SPCO'
325
-    ) {
326
-        if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
-            $debug_data = get_option($debug_key, array());
329
-            $default_data = array(
330
-                $class => $func . '() : ' . $line,
331
-                'REQ'  => $display_request ? $_REQUEST : '',
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
337
-                $debug_data[$index] = array();
338
-            }
339
-            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[$key] = self::strip_objects($value);
357
-            } else if (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[$object_class] = array();
360
-                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[$object_class]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[$object_class]['status'] = $value->status();
366
-                } else if (method_exists($value, 'status_ID')) {
367
-                    $info[$object_class]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[$key]);
370
-            }
371
-        }
372
-        return (array)$info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed      $var
379
-     * @param string     $var_name
380
-     * @param string     $file
381
-     * @param int|string $line
382
-     * @param int        $heading_tag
383
-     * @param bool       $die
384
-     * @param string     $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = '',
390
-        $line = '',
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
-        $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
405
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
406
-        if ($die) {
407
-            die($result);
408
-        }
409
-        echo $result;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * @param string $var_name
416
-     * @param string $heading_tag
417
-     * @param string $margin
418
-     * @return string
419
-     */
420
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
-    {
422
-        if (defined('EE_TESTS_DIR')) {
423
-            return "\n{$var_name}";
424
-        }
425
-        $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @param string $heading_tag
433
-     * @return string
434
-     */
435
-    protected static function headingX($heading_tag = 'h5')
436
-    {
437
-        if (defined('EE_TESTS_DIR')) {
438
-            return '';
439
-        }
440
-        return '</' . $heading_tag . '>';
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * @param string $content
447
-     * @return string
448
-     */
449
-    protected static function grey_span($content = '')
450
-    {
451
-        if (defined('EE_TESTS_DIR')) {
452
-            return $content;
453
-        }
454
-        return '<span style="color:#999">' . $content . '</span>';
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * @param string $file
461
-     * @param int    $line
462
-     * @return string
463
-     */
464
-    protected static function file_and_line($file, $line)
465
-    {
466
-        if ($file === '' || $line === '') {
467
-            return '';
468
-        }
469
-        if (defined('EE_TESTS_DIR')) {
470
-            return "\n\t(" . $file . ' line no: ' . $line . ' ) ';
471
-        }
472
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
473
-               . $file
474
-               . '<br />line no: '
475
-               . $line
476
-               . '</span>';
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * @param string $content
483
-     * @return string
484
-     */
485
-    protected static function orange_span($content = '')
486
-    {
487
-        if (defined('EE_TESTS_DIR')) {
488
-            return $content;
489
-        }
490
-        return '<span style="color:#E76700">' . $content . '</span>';
491
-    }
492
-
493
-
494
-
495
-    /**
496
-     * @param mixed $var
497
-     * @return string
498
-     */
499
-    protected static function pre_span($var)
500
-    {
501
-        ob_start();
502
-        var_dump($var);
503
-        $var = ob_get_clean();
504
-        if (defined('EE_TESTS_DIR')) {
505
-            return "\n" . $var;
506
-        }
507
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param mixed      $var
514
-     * @param string     $var_name
515
-     * @param string     $file
516
-     * @param int|string $line
517
-     * @param int        $heading_tag
518
-     * @param bool       $die
519
-     */
520
-    public static function printr(
521
-        $var,
522
-        $var_name = '',
523
-        $file = '',
524
-        $line = '',
525
-        $heading_tag = 5,
526
-        $die = false
527
-    ) {
528
-        // return;
529
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
530
-        $margin = is_admin() ? ' 180px' : '0';
531
-        //$print_r = false;
532
-        if (is_string($var)) {
533
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
534
-            return;
535
-        }
536
-        if (is_object($var)) {
537
-            $var_name = ! $var_name ? 'object' : $var_name;
538
-            //$print_r = true;
539
-        } else if (is_array($var)) {
540
-            $var_name = ! $var_name ? 'array' : $var_name;
541
-            //$print_r = true;
542
-        } else if (is_numeric($var)) {
543
-            $var_name = ! $var_name ? 'numeric' : $var_name;
544
-        } else if ($var === null) {
545
-            $var_name = ! $var_name ? 'null' : $var_name;
546
-        }
547
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
548
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
549
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
550
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
551
-                EEH_Debug_Tools::pre_span($var)
552
-            );
553
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
554
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
555
-        if ($die) {
556
-            die($result);
557
-        }
558
-        echo $result;
559
-    }
560
-
561
-
562
-
563
-    /******************** deprecated ********************/
564
-
565
-
566
-
567
-    /**
568
-     * @deprecated 4.9.39.rc.034
569
-     */
570
-    public function reset_times()
571
-    {
572
-        Benchmark::resetTimes();
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * @deprecated 4.9.39.rc.034
579
-     * @param null $timer_name
580
-     */
581
-    public function start_timer($timer_name = null)
582
-    {
583
-        Benchmark::startTimer($timer_name);
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * @deprecated 4.9.39.rc.034
590
-     * @param string $timer_name
591
-     */
592
-    public function stop_timer($timer_name = '')
593
-    {
594
-        Benchmark::stopTimer($timer_name);
595
-    }
596
-
597
-
598
-
599
-    /**
600
-     * @deprecated 4.9.39.rc.034
601
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
602
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
603
-     * @return void
604
-     */
605
-    public function measure_memory($label, $output_now = false)
606
-    {
607
-        Benchmark::measureMemory($label, $output_now);
608
-    }
609
-
610
-
611
-
612
-    /**
613
-     * @deprecated 4.9.39.rc.034
614
-     * @param int $size
615
-     * @return string
616
-     */
617
-    public function convert($size)
618
-    {
619
-        return Benchmark::convert($size);
620
-    }
621
-
622
-
623
-
624
-    /**
625
-     * @deprecated 4.9.39.rc.034
626
-     * @param bool $output_now
627
-     * @return string
628
-     */
629
-    public function show_times($output_now = true)
630
-    {
631
-        return Benchmark::displayResults($output_now);
632
-    }
633
-
634
-
635
-
636
-    /**
637
-     * @deprecated 4.9.39.rc.034
638
-     * @param string $timer_name
639
-     * @param float  $total_time
640
-     * @return string
641
-     */
642
-    public function format_time($timer_name, $total_time)
643
-    {
644
-        return Benchmark::formatTime($timer_name, $total_time);
645
-    }
20
+	/**
21
+	 *    instance of the EEH_Autoloader object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $_memory_usage_points = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EEH_Debug_Tools
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * private class constructor
53
+	 */
54
+	private function __construct()
55
+	{
56
+		// load Kint PHP debugging library
57
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
59
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
+			// so we've moved it to our test folder so that it is not included with production releases
62
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
+			require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
+		}
65
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
+		//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
+		// }
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[$tag] = $wp_filter[$tag];
134
+			if (! is_array($hook[$tag])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . $tag . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo $priority;
148
+				foreach ($function as $name => $properties) {
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[$hook_name])) {
168
+			$filters[$hook_name] = array();
169
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+				$filters[$hook_name][$priority] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[$hook_name][$priority][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__, __FUNCTION__, __LINE__
214
+					);
215
+				}
216
+			} else {
217
+				// old school attempt
218
+				file_put_contents(
219
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
+					$activation_errors
221
+				);
222
+			}
223
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
+			update_option('ee_plugin_activation_errors', $activation_errors);
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
+	 * or we want to make sure they use something the right way.
234
+	 *
235
+	 * @access public
236
+	 * @param string $function      The function that was called
237
+	 * @param string $message       A message explaining what has been done incorrectly
238
+	 * @param string $version       The version of Event Espresso where the error was added
239
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
241
+	 *                              but not have any notices appear until a later version. This allows developers
242
+	 *                              extra time to update their code before notices appear.
243
+	 * @param int    $error_type
244
+	 * @uses   trigger_error()
245
+	 */
246
+	public function doing_it_wrong(
247
+		$function,
248
+		$message,
249
+		$version,
250
+		$applies_when = '',
251
+		$error_type = null
252
+	) {
253
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
+		// because we swapped the parameter order around for the last two params,
256
+		// let's verify that some third party isn't still passing an error type value for the third param
257
+		if (is_int($applies_when)) {
258
+			$error_type = $applies_when;
259
+			$applies_when = espresso_version();
260
+		}
261
+		// if not displaying notices yet, then just leave
262
+		if (version_compare(espresso_version(), $applies_when, '<')) {
263
+			return;
264
+		}
265
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
+		$version = $version === null
267
+			? ''
268
+			: sprintf(
269
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
+				$version
271
+			);
272
+		$error_message = sprintf(
273
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
+			$function,
275
+			'<strong>',
276
+			'</strong>',
277
+			$message,
278
+			$version
279
+		);
280
+		// don't trigger error if doing ajax,
281
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
+		if (defined('DOING_AJAX') && DOING_AJAX) {
283
+			$error_message .= ' ' . esc_html__(
284
+					'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
+					'event_espresso'
286
+				);
287
+			$error_message .= '<ul><li>';
288
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
+			$error_message .= '</ul>';
290
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
+			//now we set this on the transient so it shows up on the next request.
292
+			EE_Error::get_notices(false, true);
293
+		} else {
294
+			trigger_error($error_message, $error_type);
295
+		}
296
+	}
297
+
298
+
299
+
300
+
301
+	/**
302
+	 * Logger helpers
303
+	 */
304
+	/**
305
+	 * debug
306
+	 *
307
+	 * @param string $class
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @param array  $info
311
+	 * @param bool   $display_request
312
+	 * @param string $debug_index
313
+	 * @param string $debug_key
314
+	 * @throws EE_Error
315
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
+	 */
317
+	public static function log(
318
+		$class = '',
319
+		$func = '',
320
+		$line = '',
321
+		$info = array(),
322
+		$display_request = false,
323
+		$debug_index = '',
324
+		$debug_key = 'EE_DEBUG_SPCO'
325
+	) {
326
+		if (WP_DEBUG) {
327
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+			$debug_data = get_option($debug_key, array());
329
+			$default_data = array(
330
+				$class => $func . '() : ' . $line,
331
+				'REQ'  => $display_request ? $_REQUEST : '',
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[$index])) {
337
+				$debug_data[$index] = array();
338
+			}
339
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[$key] = self::strip_objects($value);
357
+			} else if (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[$object_class] = array();
360
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[$object_class]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[$object_class]['status'] = $value->status();
366
+				} else if (method_exists($value, 'status_ID')) {
367
+					$info[$object_class]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[$key]);
370
+			}
371
+		}
372
+		return (array)$info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed      $var
379
+	 * @param string     $var_name
380
+	 * @param string     $file
381
+	 * @param int|string $line
382
+	 * @param int        $heading_tag
383
+	 * @param bool       $die
384
+	 * @param string     $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = '',
390
+		$line = '',
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
+		$result .= $is_method
402
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
405
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
406
+		if ($die) {
407
+			die($result);
408
+		}
409
+		echo $result;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * @param string $var_name
416
+	 * @param string $heading_tag
417
+	 * @param string $margin
418
+	 * @return string
419
+	 */
420
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
+	{
422
+		if (defined('EE_TESTS_DIR')) {
423
+			return "\n{$var_name}";
424
+		}
425
+		$margin = "25px 0 0 {$margin}";
426
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @param string $heading_tag
433
+	 * @return string
434
+	 */
435
+	protected static function headingX($heading_tag = 'h5')
436
+	{
437
+		if (defined('EE_TESTS_DIR')) {
438
+			return '';
439
+		}
440
+		return '</' . $heading_tag . '>';
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * @param string $content
447
+	 * @return string
448
+	 */
449
+	protected static function grey_span($content = '')
450
+	{
451
+		if (defined('EE_TESTS_DIR')) {
452
+			return $content;
453
+		}
454
+		return '<span style="color:#999">' . $content . '</span>';
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * @param string $file
461
+	 * @param int    $line
462
+	 * @return string
463
+	 */
464
+	protected static function file_and_line($file, $line)
465
+	{
466
+		if ($file === '' || $line === '') {
467
+			return '';
468
+		}
469
+		if (defined('EE_TESTS_DIR')) {
470
+			return "\n\t(" . $file . ' line no: ' . $line . ' ) ';
471
+		}
472
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
473
+			   . $file
474
+			   . '<br />line no: '
475
+			   . $line
476
+			   . '</span>';
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * @param string $content
483
+	 * @return string
484
+	 */
485
+	protected static function orange_span($content = '')
486
+	{
487
+		if (defined('EE_TESTS_DIR')) {
488
+			return $content;
489
+		}
490
+		return '<span style="color:#E76700">' . $content . '</span>';
491
+	}
492
+
493
+
494
+
495
+	/**
496
+	 * @param mixed $var
497
+	 * @return string
498
+	 */
499
+	protected static function pre_span($var)
500
+	{
501
+		ob_start();
502
+		var_dump($var);
503
+		$var = ob_get_clean();
504
+		if (defined('EE_TESTS_DIR')) {
505
+			return "\n" . $var;
506
+		}
507
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param mixed      $var
514
+	 * @param string     $var_name
515
+	 * @param string     $file
516
+	 * @param int|string $line
517
+	 * @param int        $heading_tag
518
+	 * @param bool       $die
519
+	 */
520
+	public static function printr(
521
+		$var,
522
+		$var_name = '',
523
+		$file = '',
524
+		$line = '',
525
+		$heading_tag = 5,
526
+		$die = false
527
+	) {
528
+		// return;
529
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
530
+		$margin = is_admin() ? ' 180px' : '0';
531
+		//$print_r = false;
532
+		if (is_string($var)) {
533
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
534
+			return;
535
+		}
536
+		if (is_object($var)) {
537
+			$var_name = ! $var_name ? 'object' : $var_name;
538
+			//$print_r = true;
539
+		} else if (is_array($var)) {
540
+			$var_name = ! $var_name ? 'array' : $var_name;
541
+			//$print_r = true;
542
+		} else if (is_numeric($var)) {
543
+			$var_name = ! $var_name ? 'numeric' : $var_name;
544
+		} else if ($var === null) {
545
+			$var_name = ! $var_name ? 'null' : $var_name;
546
+		}
547
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
548
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
549
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
550
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
551
+				EEH_Debug_Tools::pre_span($var)
552
+			);
553
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
554
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
555
+		if ($die) {
556
+			die($result);
557
+		}
558
+		echo $result;
559
+	}
560
+
561
+
562
+
563
+	/******************** deprecated ********************/
564
+
565
+
566
+
567
+	/**
568
+	 * @deprecated 4.9.39.rc.034
569
+	 */
570
+	public function reset_times()
571
+	{
572
+		Benchmark::resetTimes();
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * @deprecated 4.9.39.rc.034
579
+	 * @param null $timer_name
580
+	 */
581
+	public function start_timer($timer_name = null)
582
+	{
583
+		Benchmark::startTimer($timer_name);
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * @deprecated 4.9.39.rc.034
590
+	 * @param string $timer_name
591
+	 */
592
+	public function stop_timer($timer_name = '')
593
+	{
594
+		Benchmark::stopTimer($timer_name);
595
+	}
596
+
597
+
598
+
599
+	/**
600
+	 * @deprecated 4.9.39.rc.034
601
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
602
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
603
+	 * @return void
604
+	 */
605
+	public function measure_memory($label, $output_now = false)
606
+	{
607
+		Benchmark::measureMemory($label, $output_now);
608
+	}
609
+
610
+
611
+
612
+	/**
613
+	 * @deprecated 4.9.39.rc.034
614
+	 * @param int $size
615
+	 * @return string
616
+	 */
617
+	public function convert($size)
618
+	{
619
+		return Benchmark::convert($size);
620
+	}
621
+
622
+
623
+
624
+	/**
625
+	 * @deprecated 4.9.39.rc.034
626
+	 * @param bool $output_now
627
+	 * @return string
628
+	 */
629
+	public function show_times($output_now = true)
630
+	{
631
+		return Benchmark::displayResults($output_now);
632
+	}
633
+
634
+
635
+
636
+	/**
637
+	 * @deprecated 4.9.39.rc.034
638
+	 * @param string $timer_name
639
+	 * @param float  $total_time
640
+	 * @return string
641
+	 */
642
+	public function format_time($timer_name, $total_time)
643
+	{
644
+		return Benchmark::formatTime($timer_name, $total_time);
645
+	}
646 646
 
647 647
 
648 648
 
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
656 656
  */
657 657
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
658
-    function dump_wp_query()
659
-    {
660
-        global $wp_query;
661
-        d($wp_query);
662
-    }
658
+	function dump_wp_query()
659
+	{
660
+		global $wp_query;
661
+		d($wp_query);
662
+	}
663 663
 }
664 664
 /**
665 665
  * borrowed from Kint Debugger
666 666
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
667 667
  */
668 668
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
669
-    function dump_wp()
670
-    {
671
-        global $wp;
672
-        d($wp);
673
-    }
669
+	function dump_wp()
670
+	{
671
+		global $wp;
672
+		d($wp);
673
+	}
674 674
 }
675 675
 /**
676 676
  * borrowed from Kint Debugger
677 677
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
678 678
  */
679 679
 if (class_exists('Kint') && ! function_exists('dump_post')) {
680
-    function dump_post()
681
-    {
682
-        global $post;
683
-        d($post);
684
-    }
680
+	function dump_post()
681
+	{
682
+		global $post;
683
+		d($post);
684
+	}
685 685
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
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 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public static function instance()
41 41
     {
42 42
         // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
     private function __construct()
55 55
     {
56 56
         // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
57
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
58 58
             // despite EE4 having a check for an existing copy of the Kint debugging class,
59 59
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60 60
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61 61
             // so we've moved it to our test folder so that it is not included with production releases
62 62
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
63
+            require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
64 64
         }
65 65
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66 66
         //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function show_db_name()
82 82
     {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84 84
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85 85
                  . DB_NAME
86 86
                  . '</p>';
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132 132
         if ($tag) {
133 133
             $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
134
+            if ( ! is_array($hook[$tag])) {
135 135
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136 136
                 return;
137 137
             }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
138
+            echo '<h5>For Tag: '.$tag.'</h5>';
139 139
         } else {
140 140
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141 141
             ksort($hook);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
             } else {
217 217
                 // old school attempt
218 218
                 file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
219
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
220 220
                     $activation_errors
221 221
                 );
222 222
             }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
224 224
             update_option('ee_plugin_activation_errors', $activation_errors);
225 225
         }
226 226
     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         // don't trigger error if doing ajax,
281 281
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282 282
         if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
283
+            $error_message .= ' '.esc_html__(
284 284
                     'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285 285
                     'event_espresso'
286 286
                 );
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
         $debug_key = 'EE_DEBUG_SPCO'
325 325
     ) {
326 326
         if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
328 328
             $debug_data = get_option($debug_key, array());
329 329
             $default_data = array(
330
-                $class => $func . '() : ' . $line,
330
+                $class => $func.'() : '.$line,
331 331
                 'REQ'  => $display_request ? $_REQUEST : '',
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
336
+            if ( ! isset($debug_data[$index])) {
337 337
                 $debug_data[$index] = array();
338 338
             }
339 339
             $debug_data[$index][microtime()] = array_merge($default_data, $info);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 unset($info[$key]);
370 370
             }
371 371
         }
372
-        return (array)$info;
372
+        return (array) $info;
373 373
     }
374 374
 
375 375
 
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400 400
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401 401
         $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
402
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
403
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
404 404
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
405 405
         $result .= EEH_Debug_Tools::headingX($heading_tag);
406 406
         if ($die) {
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             return "\n{$var_name}";
424 424
         }
425 425
         $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
426
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
427 427
     }
428 428
 
429 429
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         if (defined('EE_TESTS_DIR')) {
438 438
             return '';
439 439
         }
440
-        return '</' . $heading_tag . '>';
440
+        return '</'.$heading_tag.'>';
441 441
     }
442 442
 
443 443
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         if (defined('EE_TESTS_DIR')) {
452 452
             return $content;
453 453
         }
454
-        return '<span style="color:#999">' . $content . '</span>';
454
+        return '<span style="color:#999">'.$content.'</span>';
455 455
     }
456 456
 
457 457
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
             return '';
468 468
         }
469 469
         if (defined('EE_TESTS_DIR')) {
470
-            return "\n\t(" . $file . ' line no: ' . $line . ' ) ';
470
+            return "\n\t(".$file.' line no: '.$line.' ) ';
471 471
         }
472 472
         return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
473 473
                . $file
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         if (defined('EE_TESTS_DIR')) {
488 488
             return $content;
489 489
         }
490
-        return '<span style="color:#E76700">' . $content . '</span>';
490
+        return '<span style="color:#E76700">'.$content.'</span>';
491 491
     }
492 492
 
493 493
 
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
         var_dump($var);
503 503
         $var = ob_get_clean();
504 504
         if (defined('EE_TESTS_DIR')) {
505
-            return "\n" . $var;
505
+            return "\n".$var;
506 506
         }
507
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
507
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
508 508
     }
509 509
 
510 510
 
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
         $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
548 548
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
549 549
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
550
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
550
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
551 551
                 EEH_Debug_Tools::pre_span($var)
552 552
             );
553 553
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 1 patch
Indentation   +464 added lines, -464 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,480 +19,480 @@  discard block
 block discarded – undo
19 19
 abstract class EE_Form_Section_Base
20 20
 {
21 21
 
22
-    /**
23
-     * the URL the form is submitted to
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_action;
28
-
29
-    /**
30
-     * POST (default) or GET
31
-     *
32
-     * @var string
33
-     */
34
-    protected $_method;
35
-
36
-    /**
37
-     * html_id and html_name are derived from this by default
38
-     *
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-    /**
44
-     * $_html_id
45
-     * @var string
46
-     */
47
-    protected $_html_id;
48
-
49
-    /**
50
-     * $_html_class
51
-     * @var string
52
-     */
53
-    protected $_html_class;
54
-
55
-    /**
56
-     * $_html_style
57
-     * @var string
58
-     */
59
-    protected $_html_style;
60
-
61
-    /**
62
-     * $_other_html_attributes
63
-     * @var string
64
-     */
65
-    protected $_other_html_attributes;
66
-
67
-    /**
68
-     * The form section of which this form section is a part
69
-     *
70
-     * @var EE_Form_Section_Proper
71
-     */
72
-    protected $_parent_section;
73
-
74
-    /**
75
-     * flag indicating that _construct_finalize has been called.
76
-     * If it has not been called and we try to use functions which require it, we call it
77
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
-     *
79
-     * @var boolean
80
-     */
81
-    protected $_construction_finalized;
82
-
83
-    /**
84
-     * Strategy for parsing the form HTML upon display
85
-     *
86
-     * @var FormHtmlFilter
87
-     */
88
-    protected $_form_html_filter;
89
-
90
-
91
-
92
-    /**
93
-     * @param array $options_array {
94
-     * @type        $name          string the name for this form section, if you want to explicitly define it
95
-     *                             }
96
-     */
97
-    public function __construct($options_array = array())
98
-    {
99
-        // used by display strategies
100
-        // assign incoming values to properties
101
-        foreach ($options_array as $key => $value) {
102
-            $key = '_' . $key;
103
-            if (property_exists($this, $key) && empty($this->{$key})) {
104
-                $this->{$key} = $value;
105
-            }
106
-        }
107
-        // set parser which allows the form section's rendered HTML to be filtered
108
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
-            $this->_form_html_filter = $options_array['form_html_filter'];
110
-        }
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param $parent_form_section
117
-     * @param $name
118
-     * @throws \EE_Error
119
-     */
120
-    protected function _construct_finalize($parent_form_section, $name)
121
-    {
122
-        $this->_construction_finalized = true;
123
-        $this->_parent_section = $parent_form_section;
124
-        if ($name !== null) {
125
-            $this->_name = $name;
126
-        }
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * make sure construction finalized was called, otherwise children might not be ready
133
-     *
134
-     * @return void
135
-     * @throws \EE_Error
136
-     */
137
-    public function ensure_construct_finalized_called()
138
-    {
139
-        if (! $this->_construction_finalized) {
140
-            $this->_construct_finalize($this->_parent_section, $this->_name);
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function action()
150
-    {
151
-        return $this->_action;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @param string $action
158
-     */
159
-    public function set_action($action)
160
-    {
161
-        $this->_action = $action;
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * @return string
168
-     */
169
-    public function method()
170
-    {
171
-        return ! empty($this->_method) ? $this->_method : 'POST';
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * @param string $method
178
-     */
179
-    public function set_method($method)
180
-    {
181
-        switch ($method) {
182
-            case 'get' :
183
-            case 'GET' :
184
-                $this->_method = 'GET';
185
-                break;
186
-            default :
187
-                $this->_method = 'POST';
188
-        }
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Sets the html_id to its default value, if none was specified in the constructor.
195
-     * Calculation involves using the name and the parent's html id
196
-     * return void
197
-     *
198
-     * @throws \EE_Error
199
-     */
200
-    protected function _set_default_html_id_if_empty()
201
-    {
202
-        if (! $this->_html_id) {
203
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
-                $this->_html_id = $this->_parent_section->html_id()
205
-                                  . '-'
206
-                                  . $this->_prep_name_for_html_id($this->name());
207
-            } else {
208
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
209
-            }
210
-        }
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * _prep_name_for_html_id
217
-     *
218
-     * @param $name
219
-     * @return string
220
-     */
221
-    private function _prep_name_for_html_id($name)
222
-    {
223
-        return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
224
-    }
22
+	/**
23
+	 * the URL the form is submitted to
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_action;
28
+
29
+	/**
30
+	 * POST (default) or GET
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $_method;
35
+
36
+	/**
37
+	 * html_id and html_name are derived from this by default
38
+	 *
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+	/**
44
+	 * $_html_id
45
+	 * @var string
46
+	 */
47
+	protected $_html_id;
48
+
49
+	/**
50
+	 * $_html_class
51
+	 * @var string
52
+	 */
53
+	protected $_html_class;
54
+
55
+	/**
56
+	 * $_html_style
57
+	 * @var string
58
+	 */
59
+	protected $_html_style;
60
+
61
+	/**
62
+	 * $_other_html_attributes
63
+	 * @var string
64
+	 */
65
+	protected $_other_html_attributes;
66
+
67
+	/**
68
+	 * The form section of which this form section is a part
69
+	 *
70
+	 * @var EE_Form_Section_Proper
71
+	 */
72
+	protected $_parent_section;
73
+
74
+	/**
75
+	 * flag indicating that _construct_finalize has been called.
76
+	 * If it has not been called and we try to use functions which require it, we call it
77
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
+	 *
79
+	 * @var boolean
80
+	 */
81
+	protected $_construction_finalized;
82
+
83
+	/**
84
+	 * Strategy for parsing the form HTML upon display
85
+	 *
86
+	 * @var FormHtmlFilter
87
+	 */
88
+	protected $_form_html_filter;
89
+
90
+
91
+
92
+	/**
93
+	 * @param array $options_array {
94
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
95
+	 *                             }
96
+	 */
97
+	public function __construct($options_array = array())
98
+	{
99
+		// used by display strategies
100
+		// assign incoming values to properties
101
+		foreach ($options_array as $key => $value) {
102
+			$key = '_' . $key;
103
+			if (property_exists($this, $key) && empty($this->{$key})) {
104
+				$this->{$key} = $value;
105
+			}
106
+		}
107
+		// set parser which allows the form section's rendered HTML to be filtered
108
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
+			$this->_form_html_filter = $options_array['form_html_filter'];
110
+		}
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param $parent_form_section
117
+	 * @param $name
118
+	 * @throws \EE_Error
119
+	 */
120
+	protected function _construct_finalize($parent_form_section, $name)
121
+	{
122
+		$this->_construction_finalized = true;
123
+		$this->_parent_section = $parent_form_section;
124
+		if ($name !== null) {
125
+			$this->_name = $name;
126
+		}
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * make sure construction finalized was called, otherwise children might not be ready
133
+	 *
134
+	 * @return void
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function ensure_construct_finalized_called()
138
+	{
139
+		if (! $this->_construction_finalized) {
140
+			$this->_construct_finalize($this->_parent_section, $this->_name);
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public function action()
150
+	{
151
+		return $this->_action;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @param string $action
158
+	 */
159
+	public function set_action($action)
160
+	{
161
+		$this->_action = $action;
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * @return string
168
+	 */
169
+	public function method()
170
+	{
171
+		return ! empty($this->_method) ? $this->_method : 'POST';
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * @param string $method
178
+	 */
179
+	public function set_method($method)
180
+	{
181
+		switch ($method) {
182
+			case 'get' :
183
+			case 'GET' :
184
+				$this->_method = 'GET';
185
+				break;
186
+			default :
187
+				$this->_method = 'POST';
188
+		}
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Sets the html_id to its default value, if none was specified in the constructor.
195
+	 * Calculation involves using the name and the parent's html id
196
+	 * return void
197
+	 *
198
+	 * @throws \EE_Error
199
+	 */
200
+	protected function _set_default_html_id_if_empty()
201
+	{
202
+		if (! $this->_html_id) {
203
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
+				$this->_html_id = $this->_parent_section->html_id()
205
+								  . '-'
206
+								  . $this->_prep_name_for_html_id($this->name());
207
+			} else {
208
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
209
+			}
210
+		}
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * _prep_name_for_html_id
217
+	 *
218
+	 * @param $name
219
+	 * @return string
220
+	 */
221
+	private function _prep_name_for_html_id($name)
222
+	{
223
+		return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
224
+	}
225 225
 
226 226
 
227 227
 
228
-    /**
229
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
-     * and call get_html when you want to output the html. Calling get_html_and_js after
232
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
-     * and so might stop working anytime.
235
-     *
236
-     * @return string
237
-     */
238
-    public function get_html_and_js()
239
-    {
240
-        return $this->get_html();
241
-    }
228
+	/**
229
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
232
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
+	 * and so might stop working anytime.
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function get_html_and_js()
239
+	{
240
+		return $this->get_html();
241
+	}
242 242
 
243 243
 
244 244
 
245
-    /**
246
-     * Gets the HTML for displaying this form section
247
-     *
248
-     * @return string
249
-     */
250
-    public abstract function get_html();
245
+	/**
246
+	 * Gets the HTML for displaying this form section
247
+	 *
248
+	 * @return string
249
+	 */
250
+	public abstract function get_html();
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * @param bool $add_pound_sign
256
-     * @return string
257
-     */
258
-    public function html_id($add_pound_sign = false)
259
-    {
260
-        $this->_set_default_html_id_if_empty();
261
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
-    }
254
+	/**
255
+	 * @param bool $add_pound_sign
256
+	 * @return string
257
+	 */
258
+	public function html_id($add_pound_sign = false)
259
+	{
260
+		$this->_set_default_html_id_if_empty();
261
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
+	}
263 263
 
264 264
 
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function html_class()
270
-    {
271
-        return $this->_html_class;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @return string
278
-     */
279
-    public function html_style()
280
-    {
281
-        return $this->_html_style;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param mixed $html_class
288
-     */
289
-    public function set_html_class($html_class)
290
-    {
291
-        $this->_html_class = $html_class;
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * @param mixed $html_id
298
-     */
299
-    public function set_html_id($html_id)
300
-    {
301
-        $this->_html_id = $html_id;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param mixed $html_style
308
-     */
309
-    public function set_html_style($html_style)
310
-    {
311
-        $this->_html_style = $html_style;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * @param string $other_html_attributes
318
-     */
319
-    public function set_other_html_attributes($other_html_attributes)
320
-    {
321
-        $this->_other_html_attributes = $other_html_attributes;
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @return string
328
-     */
329
-    public function other_html_attributes()
330
-    {
331
-        return $this->_other_html_attributes;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * Gets the name of the form section. This is not the same as the HTML name.
338
-     *
339
-     * @throws EE_Error
340
-     * @return string
341
-     */
342
-    public function name()
343
-    {
344
-        if (! $this->_construction_finalized) {
345
-            throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
-                'event_espresso'), get_class($this)));
347
-        }
348
-        return $this->_name;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * Gets the parent section
355
-     *
356
-     * @return EE_Form_Section_Proper
357
-     */
358
-    public function parent_section()
359
-    {
360
-        return $this->_parent_section;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * returns HTML for generating the opening form HTML tag (<form>)
367
-     *
368
-     * @param string $action           the URL the form is submitted to
369
-     * @param string $method           POST (default) or GET
370
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
-     * @return string
372
-     */
373
-    public function form_open($action = '', $method = '', $other_attributes = '')
374
-    {
375
-        if (! empty($action)) {
376
-            $this->set_action($action);
377
-        }
378
-        if (! empty($method)) {
379
-            $this->set_method($method);
380
-        }
381
-        $html = EEH_HTML::nl(1, 'form') . '<form';
382
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
-        $html .= ' action="' . $this->action() . '"';
384
-        $html .= ' method="' . $this->method() . '"';
385
-        $html .= $other_attributes . '>';
386
-        return $html;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * ensures that html id for form either ends in "-form" or "-frm"
393
-     * so that id doesn't conflict/collide with other elements
394
-     *
395
-     * @param string $html_id
396
-     * @return string
397
-     */
398
-    protected function get_html_id_for_form($html_id)
399
-    {
400
-        $strlen = strlen($html_id);
401
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
402
-            ? $html_id
403
-            : $html_id . '-frm';
404
-        return $html_id;
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * returns HTML for generating the closing form HTML tag (</form>)
411
-     *
412
-     * @return string
413
-     */
414
-    public function form_close()
415
-    {
416
-        return EEH_HTML::nl(-1, 'form')
417
-               . '</form>'
418
-               . EEH_HTML::nl()
419
-               . '<!-- end of ee-'
420
-               . $this->html_id()
421
-               . '-form -->'
422
-               . EEH_HTML::nl();
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
429
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
430
-     * Default does nothing, but child classes can override
431
-     *
432
-     * @return void
433
-     */
434
-    public function enqueue_js()
435
-    {
436
-        //defaults to enqueue NO js or css
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
443
-     * with it, and it will be on each form section's 'other_data' property.
444
-     * By default nothing is added, but child classes can extend this method to add something.
445
-     * Eg, if you have an input that will cause a modal dialog to appear,
446
-     * here you could add an entry like 'modal_dialog_inputs' to this array
447
-     * to map between the input's html ID and the modal dialogue's ID, so that
448
-     * your JS code will know where to find the modal dialog when the input is pressed.
449
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
450
-     *
451
-     * @param array $form_other_js_data
452
-     * @return array
453
-     */
454
-    public function get_other_js_data($form_other_js_data = array())
455
-    {
456
-        return $form_other_js_data;
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * This isn't just the name of an input, it's a path pointing to an input. The
463
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
464
-     * dot-dot-slash (../) means to ascend into the parent section.
465
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
466
-     * which will be returned.
467
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
468
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
469
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
470
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
471
-     * Etc
472
-     *
473
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
474
-     * @return EE_Form_Section_Base
475
-     */
476
-    public function find_section_from_path($form_section_path)
477
-    {
478
-        if (strpos($form_section_path, '/') === 0) {
479
-            $form_section_path = substr($form_section_path, strlen('/'));
480
-        }
481
-        if (empty($form_section_path)) {
482
-            return $this;
483
-        }
484
-        if (strpos($form_section_path, '../') === 0) {
485
-            $parent = $this->parent_section();
486
-            $form_section_path = substr($form_section_path, strlen('../'));
487
-            if ($parent instanceof EE_Form_Section_Base) {
488
-                return $parent->find_section_from_path($form_section_path);
489
-            } elseif (empty($form_section_path)) {
490
-                return $this;
491
-            }
492
-        }
493
-        //couldn't find it using simple parent following
494
-        return null;
495
-    }
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function html_class()
270
+	{
271
+		return $this->_html_class;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @return string
278
+	 */
279
+	public function html_style()
280
+	{
281
+		return $this->_html_style;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param mixed $html_class
288
+	 */
289
+	public function set_html_class($html_class)
290
+	{
291
+		$this->_html_class = $html_class;
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * @param mixed $html_id
298
+	 */
299
+	public function set_html_id($html_id)
300
+	{
301
+		$this->_html_id = $html_id;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param mixed $html_style
308
+	 */
309
+	public function set_html_style($html_style)
310
+	{
311
+		$this->_html_style = $html_style;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param string $other_html_attributes
318
+	 */
319
+	public function set_other_html_attributes($other_html_attributes)
320
+	{
321
+		$this->_other_html_attributes = $other_html_attributes;
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @return string
328
+	 */
329
+	public function other_html_attributes()
330
+	{
331
+		return $this->_other_html_attributes;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * Gets the name of the form section. This is not the same as the HTML name.
338
+	 *
339
+	 * @throws EE_Error
340
+	 * @return string
341
+	 */
342
+	public function name()
343
+	{
344
+		if (! $this->_construction_finalized) {
345
+			throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
+				'event_espresso'), get_class($this)));
347
+		}
348
+		return $this->_name;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * Gets the parent section
355
+	 *
356
+	 * @return EE_Form_Section_Proper
357
+	 */
358
+	public function parent_section()
359
+	{
360
+		return $this->_parent_section;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * returns HTML for generating the opening form HTML tag (<form>)
367
+	 *
368
+	 * @param string $action           the URL the form is submitted to
369
+	 * @param string $method           POST (default) or GET
370
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
+	 * @return string
372
+	 */
373
+	public function form_open($action = '', $method = '', $other_attributes = '')
374
+	{
375
+		if (! empty($action)) {
376
+			$this->set_action($action);
377
+		}
378
+		if (! empty($method)) {
379
+			$this->set_method($method);
380
+		}
381
+		$html = EEH_HTML::nl(1, 'form') . '<form';
382
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
+		$html .= ' action="' . $this->action() . '"';
384
+		$html .= ' method="' . $this->method() . '"';
385
+		$html .= $other_attributes . '>';
386
+		return $html;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * ensures that html id for form either ends in "-form" or "-frm"
393
+	 * so that id doesn't conflict/collide with other elements
394
+	 *
395
+	 * @param string $html_id
396
+	 * @return string
397
+	 */
398
+	protected function get_html_id_for_form($html_id)
399
+	{
400
+		$strlen = strlen($html_id);
401
+		$html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
402
+			? $html_id
403
+			: $html_id . '-frm';
404
+		return $html_id;
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * returns HTML for generating the closing form HTML tag (</form>)
411
+	 *
412
+	 * @return string
413
+	 */
414
+	public function form_close()
415
+	{
416
+		return EEH_HTML::nl(-1, 'form')
417
+			   . '</form>'
418
+			   . EEH_HTML::nl()
419
+			   . '<!-- end of ee-'
420
+			   . $this->html_id()
421
+			   . '-form -->'
422
+			   . EEH_HTML::nl();
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
429
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
430
+	 * Default does nothing, but child classes can override
431
+	 *
432
+	 * @return void
433
+	 */
434
+	public function enqueue_js()
435
+	{
436
+		//defaults to enqueue NO js or css
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
443
+	 * with it, and it will be on each form section's 'other_data' property.
444
+	 * By default nothing is added, but child classes can extend this method to add something.
445
+	 * Eg, if you have an input that will cause a modal dialog to appear,
446
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
447
+	 * to map between the input's html ID and the modal dialogue's ID, so that
448
+	 * your JS code will know where to find the modal dialog when the input is pressed.
449
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
450
+	 *
451
+	 * @param array $form_other_js_data
452
+	 * @return array
453
+	 */
454
+	public function get_other_js_data($form_other_js_data = array())
455
+	{
456
+		return $form_other_js_data;
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * This isn't just the name of an input, it's a path pointing to an input. The
463
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
464
+	 * dot-dot-slash (../) means to ascend into the parent section.
465
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
466
+	 * which will be returned.
467
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
468
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
469
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
470
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
471
+	 * Etc
472
+	 *
473
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
474
+	 * @return EE_Form_Section_Base
475
+	 */
476
+	public function find_section_from_path($form_section_path)
477
+	{
478
+		if (strpos($form_section_path, '/') === 0) {
479
+			$form_section_path = substr($form_section_path, strlen('/'));
480
+		}
481
+		if (empty($form_section_path)) {
482
+			return $this;
483
+		}
484
+		if (strpos($form_section_path, '../') === 0) {
485
+			$parent = $this->parent_section();
486
+			$form_section_path = substr($form_section_path, strlen('../'));
487
+			if ($parent instanceof EE_Form_Section_Base) {
488
+				return $parent->find_section_from_path($form_section_path);
489
+			} elseif (empty($form_section_path)) {
490
+				return $this;
491
+			}
492
+		}
493
+		//couldn't find it using simple parent following
494
+		return null;
495
+	}
496 496
 
497 497
 
498 498
 }
Please login to merge, or discard this patch.