Completed
Branch EDTR/master (3006ba)
by
unknown
11:46 queued 54s
created
venues/templates/venue_virtual_location_metabox_content.template.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
                         <?php esc_html_e('URL of Event:', 'event_espresso'); ?>
8 8
                     </label>
9 9
                     <?php //phpcs:disable Generic.Files.LineLength.TooLong
10
-                    // no new lines within <textarea> here because they'll output whitespace ?>
10
+					// no new lines within <textarea> here because they'll output whitespace ?>
11 11
                     <textarea id="url-event" cols="30" rows="4" tabindex="112" name="vnu_virtual_url"><?php $_venue->f('VNU_virtual_url'); ?></textarea>
12 12
                     <?php //phpcs:enable ?>
13 13
                 </p>
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 2 patches
Indentation   +557 added lines, -557 removed lines patch added patch discarded remove patch
@@ -12,566 +12,566 @@
 block discarded – undo
12 12
 class EE_Event_Registrations_List_Table extends EE_Admin_List_Table
13 13
 {
14 14
 
15
-    /**
16
-     * This property will hold the related Datetimes on an event IF the event id is included in the request.
17
-     *
18
-     * @var EE_Datetime[]
19
-     */
20
-    protected $_dtts_for_event = array();
21
-
22
-
23
-    /**
24
-     * The event if one is specified in the request
25
-     *
26
-     * @var EE_Event
27
-     */
28
-    protected $_evt = null;
29
-
30
-
31
-    /**
32
-     * The DTT_ID if the current view has a specified datetime.
33
-     *
34
-     * @var int $_cur_dtt_id
35
-     */
36
-    protected $_cur_dtt_id = 0;
37
-
38
-
39
-    /**
40
-     * EE_Event_Registrations_List_Table constructor.
41
-     *
42
-     * @param \Registrations_Admin_Page $admin_page
43
-     */
44
-    public function __construct($admin_page)
45
-    {
46
-        parent::__construct($admin_page);
47
-        $this->_status = $this->_admin_page->get_registration_status_array();
48
-    }
49
-
50
-
51
-    protected function _setup_data()
52
-    {
53
-        $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
-            : $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55
-        $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56
-            $this->_per_page,
57
-            true
58
-        ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59
-    }
60
-
61
-
62
-    protected function _set_properties()
63
-    {
64
-        $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
65
-        $this->_wp_list_args = array(
66
-            'singular' => __('registrant', 'event_espresso'),
67
-            'plural'   => __('registrants', 'event_espresso'),
68
-            'ajax'     => true,
69
-            'screen'   => $this->_admin_page->get_current_screen()->id,
70
-        );
71
-        $columns = array();
72
-        // $columns['_Reg_Status'] = '';
73
-        $this->_columns = array(
74
-            '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
75
-            'ATT_name'            => __('Registrant', 'event_espresso'),
76
-            'ATT_email'           => __('Email Address', 'event_espresso'),
77
-            'Event'               => __('Event', 'event_espresso'),
78
-            'PRC_name'            => __('TKT Option', 'event_espresso'),
79
-            '_REG_final_price'    => __('Price', 'event_espresso'),
80
-            'TXN_paid'            => __('Paid', 'event_espresso'),
81
-            'TXN_total'           => __('Total', 'event_espresso'),
82
-        );
83
-        // Add/remove columns when an event has been selected
84
-        if (! empty($evt_id)) {
85
-            // Render a checkbox column
86
-            $columns['cb'] = '<input type="checkbox" />';
87
-            $this->_has_checkbox_column = true;
88
-            // Remove the 'Event' column
89
-            unset($this->_columns['Event']);
90
-        }
91
-        $this->_columns = array_merge($columns, $this->_columns);
92
-        $this->_primary_column = '_REG_att_checked_in';
93
-        if (! empty($evt_id)
94
-            && EE_Registry::instance()->CAP->current_user_can(
95
-                'ee_read_registrations',
96
-                'espresso_registrations_registrations_reports',
97
-                $evt_id
98
-            )
99
-        ) {
100
-            $this->_bottom_buttons = array(
101
-                'report' => array(
102
-                    'route'         => 'registrations_report',
103
-                    'extra_request' =>
104
-                        array(
105
-                            'EVT_ID'     => $evt_id,
106
-                            'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
107
-                        ),
108
-                ),
109
-            );
110
-        }
111
-        $this->_bottom_buttons['report_filtered'] = array(
112
-            'route'         => 'registrations_checkin_report',
113
-            'extra_request' => array(
114
-                'use_filters' => true,
115
-                'filters'     => array_merge(
116
-                    array(
117
-                        'EVT_ID' => $evt_id,
118
-                    ),
119
-                    array_diff_key(
120
-                        $this->_req_data,
121
-                        array_flip(
122
-                            array(
123
-                                'page',
124
-                                'action',
125
-                                'default_nonce',
126
-                            )
127
-                        )
128
-                    )
129
-                ),
130
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
131
-            ),
132
-        );
133
-        $this->_sortable_columns = array(
134
-            /**
135
-             * Allows users to change the default sort if they wish.
136
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
137
-             *
138
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
139
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
140
-             * for a specific list table you can use the provided reference to this object instance.
141
-             */
142
-            'ATT_name' => array(
143
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
144
-                true,
145
-                $this,
146
-            )
147
-                ? array('ATT_lname' => true)
148
-                : array('ATT_fname' => true),
149
-            'Event'    => array('Event.EVT_name' => false),
150
-        );
151
-        $this->_hidden_columns = array();
152
-        $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
153
-        $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
154
-    }
155
-
156
-
157
-    /**
158
-     * @param \EE_Registration $item
159
-     * @return string
160
-     */
161
-    protected function _get_row_class($item)
162
-    {
163
-        $class = parent::_get_row_class($item);
164
-        // add status class
165
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
166
-        if ($this->_has_checkbox_column) {
167
-            $class .= ' has-checkbox-column';
168
-        }
169
-        return $class;
170
-    }
171
-
172
-
173
-    /**
174
-     * @return array
175
-     * @throws \EE_Error
176
-     */
177
-    protected function _get_table_filters()
178
-    {
179
-        $filters = $where = array();
180
-        $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
181
-        if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
182
-            // this means we don't have an event so let's setup a filter dropdown for all the events to select
183
-            // note possible capability restrictions
184
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
185
-                $where['status**'] = array('!=', 'private');
186
-            }
187
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
188
-                $where['EVT_wp_user'] = get_current_user_id();
189
-            }
190
-            $events = EEM_Event::instance()->get_all(
191
-                array(
192
-                    $where,
193
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
194
-                )
195
-            );
196
-            $evts[] = array(
197
-                'id'   => 0,
198
-                'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
199
-            );
200
-            $checked = 'checked';
201
-            /** @var EE_Event $evt */
202
-            foreach ($events as $evt) {
203
-                // any registrations for this event?
204
-                if (! $evt->get_count_of_all_registrations()) {
205
-                    continue;
206
-                }
207
-                $evts[] = array(
208
-                    'id'    => $evt->ID(),
209
-                    'text'  => apply_filters(
210
-                        'FHEE__EE_Event_Registrations___get_table_filters__event_name',
211
-                        $evt->get('EVT_name'),
212
-                        $evt
213
-                    ),
214
-                    'class' => $evt->is_expired() ? 'ee-expired-event' : '',
215
-                );
216
-                if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
217
-                    $checked = '';
218
-                }
219
-            }
220
-            $event_filter = '<div class="ee-event-filter">';
221
-            $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
222
-            $event_filter .= '<span class="ee-event-filter-toggle">';
223
-            $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
224
-            $event_filter .= __('Hide Expired Events', 'event_espresso');
225
-            $event_filter .= '</span>';
226
-            $event_filter .= '</div>';
227
-            $filters[] = $event_filter;
228
-        }
229
-        if (! empty($this->_dtts_for_event)) {
230
-            // DTT datetimes filter
231
-            $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
232
-            if (count($this->_dtts_for_event) > 1) {
233
-                $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
234
-                foreach ($this->_dtts_for_event as $dtt) {
235
-                    $datetime_string = $dtt->name();
236
-                    $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
237
-                    $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
238
-                    $dtts[ $dtt->ID() ] = $datetime_string;
239
-                }
240
-                $input = new EE_Select_Input(
241
-                    $dtts,
242
-                    array(
243
-                        'html_name' => 'DTT_ID',
244
-                        'html_id'   => 'DTT_ID',
245
-                        'default'   => $this->_cur_dtt_id,
246
-                    )
247
-                );
248
-                $filters[] = $input->get_html_for_input();
249
-                $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
250
-            }
251
-        }
252
-        return $filters;
253
-    }
254
-
255
-
256
-    protected function _add_view_counts()
257
-    {
258
-        $this->_views['all']['count'] = $this->_get_total_event_attendees();
259
-    }
260
-
261
-
262
-    /**
263
-     * @return int
264
-     * @throws \EE_Error
265
-     */
266
-    protected function _get_total_event_attendees()
267
-    {
268
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
269
-        $DTT_ID = $this->_cur_dtt_id;
270
-        $query_params = array();
271
-        if ($EVT_ID) {
272
-            $query_params[0]['EVT_ID'] = $EVT_ID;
273
-        }
274
-        // if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
275
-        if ($DTT_ID) {
276
-            $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
277
-        }
278
-        $status_ids_array = apply_filters(
279
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
280
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
281
-        );
282
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
283
-        return EEM_Registration::instance()->count($query_params);
284
-    }
285
-
286
-
287
-    /**
288
-     * @param \EE_Registration $item
289
-     * @return string
290
-     */
291
-    public function column__Reg_Status(EE_Registration $item)
292
-    {
293
-        return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
294
-    }
295
-
296
-
297
-    /**
298
-     * @param \EE_Registration $item
299
-     * @return string
300
-     * @throws \EE_Error
301
-     */
302
-    public function column_cb($item)
303
-    {
304
-        return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
305
-    }
306
-
307
-
308
-    /**
309
-     * column_REG_att_checked_in
310
-     *
311
-     * @param EE_Registration $item
312
-     * @return string
313
-     * @throws EE_Error
314
-     * @throws InvalidArgumentException
315
-     * @throws InvalidDataTypeException
316
-     * @throws InvalidInterfaceException
317
-     */
318
-    public function column__REG_att_checked_in(EE_Registration $item)
319
-    {
320
-        $attendee = $item->attendee();
321
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
322
-
323
-        if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
324
-            $latest_related_datetime = $item->get_latest_related_datetime();
325
-            if ($latest_related_datetime instanceof EE_Datetime) {
326
-                $this->_cur_dtt_id = $latest_related_datetime->ID();
327
-            }
328
-        }
329
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
330
-            $item,
331
-            $this->_cur_dtt_id
332
-        );
333
-        $nonce = wp_create_nonce('checkin_nonce');
334
-        $toggle_active = ! empty($this->_cur_dtt_id)
335
-                         && EE_Registry::instance()->CAP->current_user_can(
336
-                             'ee_edit_checkin',
337
-                             'espresso_registrations_toggle_checkin_status',
338
-                             $item->ID()
339
-                         )
340
-            ? ' clickable trigger-checkin'
341
-            : '';
342
-        $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
343
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
344
-               . ' data-_regid="' . $item->ID() . '"'
345
-               . ' data-dttid="' . $this->_cur_dtt_id . '"'
346
-               . ' data-nonce="' . $nonce . '">'
347
-               . '</span>'
348
-               . $mobile_view_content;
349
-    }
350
-
351
-
352
-    /**
353
-     * @param \EE_Registration $item
354
-     * @return mixed|string|void
355
-     * @throws \EE_Error
356
-     */
357
-    public function column_ATT_name(EE_Registration $item)
358
-    {
359
-        $attendee = $item->attendee();
360
-        if (! $attendee instanceof EE_Attendee) {
361
-            return __('No contact record for this registration.', 'event_espresso');
362
-        }
363
-        // edit attendee link
364
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
365
-            array('action' => 'view_registration', '_REG_ID' => $item->ID()),
366
-            REG_ADMIN_URL
367
-        );
368
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
369
-            'ee_edit_contacts',
370
-            'espresso_registrations_edit_attendee'
371
-        )
372
-            ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
373
-              . $item->attendee()->full_name()
374
-              . '</a>'
375
-            : $item->attendee()->full_name();
376
-        $name_link .= $item->count() === 1
377
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
378
-            : '';
379
-        // add group details
380
-        $name_link .= '&nbsp;' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
381
-        // add regcode
382
-        $link = EE_Admin_Page::add_query_args_and_nonce(
383
-            array('action' => 'view_registration', '_REG_ID' => $item->ID()),
384
-            REG_ADMIN_URL
385
-        );
386
-        $name_link .= '<br>';
387
-        $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
388
-            'ee_read_registration',
389
-            'view_registration',
390
-            $item->ID()
391
-        )
392
-            ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
393
-              . $item->reg_code()
394
-              . '</a>'
395
-            : $item->reg_code();
396
-        // status
397
-        $name_link .= '<br><span class="ee-status-text-small">';
398
-        $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
399
-        $name_link .= '</span>';
400
-        $actions = array();
401
-        $DTT_ID = $this->_cur_dtt_id;
402
-        $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
403
-            ? $item->get_latest_related_datetime()
404
-            : null;
405
-        $DTT_ID = $latest_related_datetime instanceof EE_Datetime
406
-            ? $latest_related_datetime->ID()
407
-            : $DTT_ID;
408
-        if (! empty($DTT_ID)
409
-            && EE_Registry::instance()->CAP->current_user_can(
410
-                'ee_read_checkins',
411
-                'espresso_registrations_registration_checkins'
412
-            )
413
-        ) {
414
-            $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
415
-                array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID),
416
-                REG_ADMIN_URL
417
-            );
418
-            // get the timestamps for this registration's checkins, related to the selected datetime
419
-            $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
420
-            if (! empty($timestamps)) {
421
-                // get the last timestamp
422
-                $last_timestamp = end($timestamps);
423
-                // checked in or checked out?
424
-                $checkin_status = $last_timestamp->get('CHK_in')
425
-                    ? esc_html__('Checked In', 'event_espresso')
426
-                    : esc_html__('Checked Out', 'event_espresso');
427
-                // get timestamp string
428
-                $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
429
-                $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
430
-                                      . esc_attr__(
431
-                                          'View this registrant\'s check-ins/checkouts for the datetime',
432
-                                          'event_espresso'
433
-                                      ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
434
-            }
435
-        }
436
-        return (! empty($DTT_ID) && ! empty($timestamps))
437
-            ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
438
-            : $name_link;
439
-    }
440
-
441
-
442
-    /**
443
-     * @param \EE_Registration $item
444
-     * @return string
445
-     */
446
-    public function column_ATT_email(EE_Registration $item)
447
-    {
448
-        $attendee = $item->attendee();
449
-        return $attendee instanceof EE_Attendee ? $attendee->email() : '';
450
-    }
451
-
452
-
453
-    /**
454
-     * @param \EE_Registration $item
455
-     * @return bool|string
456
-     * @throws \EE_Error
457
-     */
458
-    public function column_Event(EE_Registration $item)
459
-    {
460
-        try {
461
-            $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
462
-            $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
463
-                array('action' => 'event_registrations', 'event_id' => $event->ID()),
464
-                REG_ADMIN_URL
465
-            );
466
-            $event_label = EE_Registry::instance()->CAP->current_user_can(
467
-                'ee_read_checkins',
468
-                'espresso_registrations_registration_checkins'
469
-            ) ? '<a href="' . $chkin_lnk_url . '" title="'
470
-                . esc_attr__(
471
-                    'View Checkins for this Event',
472
-                    'event_espresso'
473
-                ) . '">' . $event->name() . '</a>' : $event->name();
474
-        } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
475
-            $event_label = esc_html__('Unknown', 'event_espresso');
476
-        }
477
-        return $event_label;
478
-    }
479
-
480
-
481
-    /**
482
-     * @param \EE_Registration $item
483
-     * @return mixed|string|void
484
-     */
485
-    public function column_PRC_name(EE_Registration $item)
486
-    {
487
-        return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
488
-    }
489
-
490
-
491
-    /**
492
-     * column_REG_final_price
493
-     *
494
-     * @param \EE_Registration $item
495
-     * @return string
496
-     */
497
-    public function column__REG_final_price(EE_Registration $item)
498
-    {
499
-        return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
500
-    }
501
-
502
-
503
-    /**
504
-     * column_TXN_paid
505
-     *
506
-     * @param \EE_Registration $item
507
-     * @return string
508
-     * @throws \EE_Error
509
-     */
510
-    public function column_TXN_paid(EE_Registration $item)
511
-    {
512
-        if ($item->count() === 1) {
513
-            if ($item->transaction()->paid() >= $item->transaction()->total()) {
514
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
515
-            } else {
516
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
517
-                    array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
518
-                    TXN_ADMIN_URL
519
-                );
520
-                return EE_Registry::instance()->CAP->current_user_can(
521
-                    'ee_read_transaction',
522
-                    'espresso_transactions_view_transaction'
523
-                ) ? '
15
+	/**
16
+	 * This property will hold the related Datetimes on an event IF the event id is included in the request.
17
+	 *
18
+	 * @var EE_Datetime[]
19
+	 */
20
+	protected $_dtts_for_event = array();
21
+
22
+
23
+	/**
24
+	 * The event if one is specified in the request
25
+	 *
26
+	 * @var EE_Event
27
+	 */
28
+	protected $_evt = null;
29
+
30
+
31
+	/**
32
+	 * The DTT_ID if the current view has a specified datetime.
33
+	 *
34
+	 * @var int $_cur_dtt_id
35
+	 */
36
+	protected $_cur_dtt_id = 0;
37
+
38
+
39
+	/**
40
+	 * EE_Event_Registrations_List_Table constructor.
41
+	 *
42
+	 * @param \Registrations_Admin_Page $admin_page
43
+	 */
44
+	public function __construct($admin_page)
45
+	{
46
+		parent::__construct($admin_page);
47
+		$this->_status = $this->_admin_page->get_registration_status_array();
48
+	}
49
+
50
+
51
+	protected function _setup_data()
52
+	{
53
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55
+		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56
+			$this->_per_page,
57
+			true
58
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59
+	}
60
+
61
+
62
+	protected function _set_properties()
63
+	{
64
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
65
+		$this->_wp_list_args = array(
66
+			'singular' => __('registrant', 'event_espresso'),
67
+			'plural'   => __('registrants', 'event_espresso'),
68
+			'ajax'     => true,
69
+			'screen'   => $this->_admin_page->get_current_screen()->id,
70
+		);
71
+		$columns = array();
72
+		// $columns['_Reg_Status'] = '';
73
+		$this->_columns = array(
74
+			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
75
+			'ATT_name'            => __('Registrant', 'event_espresso'),
76
+			'ATT_email'           => __('Email Address', 'event_espresso'),
77
+			'Event'               => __('Event', 'event_espresso'),
78
+			'PRC_name'            => __('TKT Option', 'event_espresso'),
79
+			'_REG_final_price'    => __('Price', 'event_espresso'),
80
+			'TXN_paid'            => __('Paid', 'event_espresso'),
81
+			'TXN_total'           => __('Total', 'event_espresso'),
82
+		);
83
+		// Add/remove columns when an event has been selected
84
+		if (! empty($evt_id)) {
85
+			// Render a checkbox column
86
+			$columns['cb'] = '<input type="checkbox" />';
87
+			$this->_has_checkbox_column = true;
88
+			// Remove the 'Event' column
89
+			unset($this->_columns['Event']);
90
+		}
91
+		$this->_columns = array_merge($columns, $this->_columns);
92
+		$this->_primary_column = '_REG_att_checked_in';
93
+		if (! empty($evt_id)
94
+			&& EE_Registry::instance()->CAP->current_user_can(
95
+				'ee_read_registrations',
96
+				'espresso_registrations_registrations_reports',
97
+				$evt_id
98
+			)
99
+		) {
100
+			$this->_bottom_buttons = array(
101
+				'report' => array(
102
+					'route'         => 'registrations_report',
103
+					'extra_request' =>
104
+						array(
105
+							'EVT_ID'     => $evt_id,
106
+							'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
107
+						),
108
+				),
109
+			);
110
+		}
111
+		$this->_bottom_buttons['report_filtered'] = array(
112
+			'route'         => 'registrations_checkin_report',
113
+			'extra_request' => array(
114
+				'use_filters' => true,
115
+				'filters'     => array_merge(
116
+					array(
117
+						'EVT_ID' => $evt_id,
118
+					),
119
+					array_diff_key(
120
+						$this->_req_data,
121
+						array_flip(
122
+							array(
123
+								'page',
124
+								'action',
125
+								'default_nonce',
126
+							)
127
+						)
128
+					)
129
+				),
130
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
131
+			),
132
+		);
133
+		$this->_sortable_columns = array(
134
+			/**
135
+			 * Allows users to change the default sort if they wish.
136
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
137
+			 *
138
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
139
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
140
+			 * for a specific list table you can use the provided reference to this object instance.
141
+			 */
142
+			'ATT_name' => array(
143
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
144
+				true,
145
+				$this,
146
+			)
147
+				? array('ATT_lname' => true)
148
+				: array('ATT_fname' => true),
149
+			'Event'    => array('Event.EVT_name' => false),
150
+		);
151
+		$this->_hidden_columns = array();
152
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
153
+		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param \EE_Registration $item
159
+	 * @return string
160
+	 */
161
+	protected function _get_row_class($item)
162
+	{
163
+		$class = parent::_get_row_class($item);
164
+		// add status class
165
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
166
+		if ($this->_has_checkbox_column) {
167
+			$class .= ' has-checkbox-column';
168
+		}
169
+		return $class;
170
+	}
171
+
172
+
173
+	/**
174
+	 * @return array
175
+	 * @throws \EE_Error
176
+	 */
177
+	protected function _get_table_filters()
178
+	{
179
+		$filters = $where = array();
180
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
181
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
182
+			// this means we don't have an event so let's setup a filter dropdown for all the events to select
183
+			// note possible capability restrictions
184
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
185
+				$where['status**'] = array('!=', 'private');
186
+			}
187
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
188
+				$where['EVT_wp_user'] = get_current_user_id();
189
+			}
190
+			$events = EEM_Event::instance()->get_all(
191
+				array(
192
+					$where,
193
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
194
+				)
195
+			);
196
+			$evts[] = array(
197
+				'id'   => 0,
198
+				'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
199
+			);
200
+			$checked = 'checked';
201
+			/** @var EE_Event $evt */
202
+			foreach ($events as $evt) {
203
+				// any registrations for this event?
204
+				if (! $evt->get_count_of_all_registrations()) {
205
+					continue;
206
+				}
207
+				$evts[] = array(
208
+					'id'    => $evt->ID(),
209
+					'text'  => apply_filters(
210
+						'FHEE__EE_Event_Registrations___get_table_filters__event_name',
211
+						$evt->get('EVT_name'),
212
+						$evt
213
+					),
214
+					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
215
+				);
216
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
217
+					$checked = '';
218
+				}
219
+			}
220
+			$event_filter = '<div class="ee-event-filter">';
221
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
222
+			$event_filter .= '<span class="ee-event-filter-toggle">';
223
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
224
+			$event_filter .= __('Hide Expired Events', 'event_espresso');
225
+			$event_filter .= '</span>';
226
+			$event_filter .= '</div>';
227
+			$filters[] = $event_filter;
228
+		}
229
+		if (! empty($this->_dtts_for_event)) {
230
+			// DTT datetimes filter
231
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
232
+			if (count($this->_dtts_for_event) > 1) {
233
+				$dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
234
+				foreach ($this->_dtts_for_event as $dtt) {
235
+					$datetime_string = $dtt->name();
236
+					$datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
237
+					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
238
+					$dtts[ $dtt->ID() ] = $datetime_string;
239
+				}
240
+				$input = new EE_Select_Input(
241
+					$dtts,
242
+					array(
243
+						'html_name' => 'DTT_ID',
244
+						'html_id'   => 'DTT_ID',
245
+						'default'   => $this->_cur_dtt_id,
246
+					)
247
+				);
248
+				$filters[] = $input->get_html_for_input();
249
+				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
250
+			}
251
+		}
252
+		return $filters;
253
+	}
254
+
255
+
256
+	protected function _add_view_counts()
257
+	{
258
+		$this->_views['all']['count'] = $this->_get_total_event_attendees();
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return int
264
+	 * @throws \EE_Error
265
+	 */
266
+	protected function _get_total_event_attendees()
267
+	{
268
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
269
+		$DTT_ID = $this->_cur_dtt_id;
270
+		$query_params = array();
271
+		if ($EVT_ID) {
272
+			$query_params[0]['EVT_ID'] = $EVT_ID;
273
+		}
274
+		// if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
275
+		if ($DTT_ID) {
276
+			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
277
+		}
278
+		$status_ids_array = apply_filters(
279
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
280
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
281
+		);
282
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
283
+		return EEM_Registration::instance()->count($query_params);
284
+	}
285
+
286
+
287
+	/**
288
+	 * @param \EE_Registration $item
289
+	 * @return string
290
+	 */
291
+	public function column__Reg_Status(EE_Registration $item)
292
+	{
293
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
294
+	}
295
+
296
+
297
+	/**
298
+	 * @param \EE_Registration $item
299
+	 * @return string
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function column_cb($item)
303
+	{
304
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
305
+	}
306
+
307
+
308
+	/**
309
+	 * column_REG_att_checked_in
310
+	 *
311
+	 * @param EE_Registration $item
312
+	 * @return string
313
+	 * @throws EE_Error
314
+	 * @throws InvalidArgumentException
315
+	 * @throws InvalidDataTypeException
316
+	 * @throws InvalidInterfaceException
317
+	 */
318
+	public function column__REG_att_checked_in(EE_Registration $item)
319
+	{
320
+		$attendee = $item->attendee();
321
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
322
+
323
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
324
+			$latest_related_datetime = $item->get_latest_related_datetime();
325
+			if ($latest_related_datetime instanceof EE_Datetime) {
326
+				$this->_cur_dtt_id = $latest_related_datetime->ID();
327
+			}
328
+		}
329
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
330
+			$item,
331
+			$this->_cur_dtt_id
332
+		);
333
+		$nonce = wp_create_nonce('checkin_nonce');
334
+		$toggle_active = ! empty($this->_cur_dtt_id)
335
+						 && EE_Registry::instance()->CAP->current_user_can(
336
+							 'ee_edit_checkin',
337
+							 'espresso_registrations_toggle_checkin_status',
338
+							 $item->ID()
339
+						 )
340
+			? ' clickable trigger-checkin'
341
+			: '';
342
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
343
+		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
344
+			   . ' data-_regid="' . $item->ID() . '"'
345
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
346
+			   . ' data-nonce="' . $nonce . '">'
347
+			   . '</span>'
348
+			   . $mobile_view_content;
349
+	}
350
+
351
+
352
+	/**
353
+	 * @param \EE_Registration $item
354
+	 * @return mixed|string|void
355
+	 * @throws \EE_Error
356
+	 */
357
+	public function column_ATT_name(EE_Registration $item)
358
+	{
359
+		$attendee = $item->attendee();
360
+		if (! $attendee instanceof EE_Attendee) {
361
+			return __('No contact record for this registration.', 'event_espresso');
362
+		}
363
+		// edit attendee link
364
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
365
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
366
+			REG_ADMIN_URL
367
+		);
368
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
369
+			'ee_edit_contacts',
370
+			'espresso_registrations_edit_attendee'
371
+		)
372
+			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
373
+			  . $item->attendee()->full_name()
374
+			  . '</a>'
375
+			: $item->attendee()->full_name();
376
+		$name_link .= $item->count() === 1
377
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
378
+			: '';
379
+		// add group details
380
+		$name_link .= '&nbsp;' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
381
+		// add regcode
382
+		$link = EE_Admin_Page::add_query_args_and_nonce(
383
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
384
+			REG_ADMIN_URL
385
+		);
386
+		$name_link .= '<br>';
387
+		$name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
388
+			'ee_read_registration',
389
+			'view_registration',
390
+			$item->ID()
391
+		)
392
+			? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
393
+			  . $item->reg_code()
394
+			  . '</a>'
395
+			: $item->reg_code();
396
+		// status
397
+		$name_link .= '<br><span class="ee-status-text-small">';
398
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
399
+		$name_link .= '</span>';
400
+		$actions = array();
401
+		$DTT_ID = $this->_cur_dtt_id;
402
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
403
+			? $item->get_latest_related_datetime()
404
+			: null;
405
+		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
406
+			? $latest_related_datetime->ID()
407
+			: $DTT_ID;
408
+		if (! empty($DTT_ID)
409
+			&& EE_Registry::instance()->CAP->current_user_can(
410
+				'ee_read_checkins',
411
+				'espresso_registrations_registration_checkins'
412
+			)
413
+		) {
414
+			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
415
+				array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID),
416
+				REG_ADMIN_URL
417
+			);
418
+			// get the timestamps for this registration's checkins, related to the selected datetime
419
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
420
+			if (! empty($timestamps)) {
421
+				// get the last timestamp
422
+				$last_timestamp = end($timestamps);
423
+				// checked in or checked out?
424
+				$checkin_status = $last_timestamp->get('CHK_in')
425
+					? esc_html__('Checked In', 'event_espresso')
426
+					: esc_html__('Checked Out', 'event_espresso');
427
+				// get timestamp string
428
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
429
+				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
430
+									  . esc_attr__(
431
+										  'View this registrant\'s check-ins/checkouts for the datetime',
432
+										  'event_espresso'
433
+									  ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
434
+			}
435
+		}
436
+		return (! empty($DTT_ID) && ! empty($timestamps))
437
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
438
+			: $name_link;
439
+	}
440
+
441
+
442
+	/**
443
+	 * @param \EE_Registration $item
444
+	 * @return string
445
+	 */
446
+	public function column_ATT_email(EE_Registration $item)
447
+	{
448
+		$attendee = $item->attendee();
449
+		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
450
+	}
451
+
452
+
453
+	/**
454
+	 * @param \EE_Registration $item
455
+	 * @return bool|string
456
+	 * @throws \EE_Error
457
+	 */
458
+	public function column_Event(EE_Registration $item)
459
+	{
460
+		try {
461
+			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
462
+			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
463
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
464
+				REG_ADMIN_URL
465
+			);
466
+			$event_label = EE_Registry::instance()->CAP->current_user_can(
467
+				'ee_read_checkins',
468
+				'espresso_registrations_registration_checkins'
469
+			) ? '<a href="' . $chkin_lnk_url . '" title="'
470
+				. esc_attr__(
471
+					'View Checkins for this Event',
472
+					'event_espresso'
473
+				) . '">' . $event->name() . '</a>' : $event->name();
474
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
475
+			$event_label = esc_html__('Unknown', 'event_espresso');
476
+		}
477
+		return $event_label;
478
+	}
479
+
480
+
481
+	/**
482
+	 * @param \EE_Registration $item
483
+	 * @return mixed|string|void
484
+	 */
485
+	public function column_PRC_name(EE_Registration $item)
486
+	{
487
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
488
+	}
489
+
490
+
491
+	/**
492
+	 * column_REG_final_price
493
+	 *
494
+	 * @param \EE_Registration $item
495
+	 * @return string
496
+	 */
497
+	public function column__REG_final_price(EE_Registration $item)
498
+	{
499
+		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
500
+	}
501
+
502
+
503
+	/**
504
+	 * column_TXN_paid
505
+	 *
506
+	 * @param \EE_Registration $item
507
+	 * @return string
508
+	 * @throws \EE_Error
509
+	 */
510
+	public function column_TXN_paid(EE_Registration $item)
511
+	{
512
+		if ($item->count() === 1) {
513
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
514
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
515
+			} else {
516
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
517
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
518
+					TXN_ADMIN_URL
519
+				);
520
+				return EE_Registry::instance()->CAP->current_user_can(
521
+					'ee_read_transaction',
522
+					'espresso_transactions_view_transaction'
523
+				) ? '
524 524
 				<span class="reg-pad-rght">
525 525
 					<a class="status-'
526
-                    . $item->transaction()->status_ID()
527
-                    . '" href="'
528
-                    . $view_txn_lnk_url
529
-                    . '"  title="'
530
-                    . esc_attr__('View Transaction', 'event_espresso')
531
-                    . '">
526
+					. $item->transaction()->status_ID()
527
+					. '" href="'
528
+					. $view_txn_lnk_url
529
+					. '"  title="'
530
+					. esc_attr__('View Transaction', 'event_espresso')
531
+					. '">
532 532
 						'
533
-                    . $item->transaction()->pretty_paid()
534
-                    . '
533
+					. $item->transaction()->pretty_paid()
534
+					. '
535 535
 					</a>
536 536
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
537
-            }
538
-        } else {
539
-            return '<span class="reg-pad-rght"></span>';
540
-        }
541
-    }
542
-
543
-
544
-    /**
545
-     *        column_TXN_total
546
-     *
547
-     * @param \EE_Registration $item
548
-     * @return string
549
-     * @throws \EE_Error
550
-     */
551
-    public function column_TXN_total(EE_Registration $item)
552
-    {
553
-        $txn = $item->transaction();
554
-        $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
555
-        if ($item->get('REG_count') === 1) {
556
-            $line_total_obj = $txn->total_line_item();
557
-            $txn_total = $line_total_obj instanceof EE_Line_Item
558
-                ? $line_total_obj->get_pretty('LIN_total')
559
-                : __(
560
-                    'View Transaction',
561
-                    'event_espresso'
562
-                );
563
-            return EE_Registry::instance()->CAP->current_user_can(
564
-                'ee_read_transaction',
565
-                'espresso_transactions_view_transaction'
566
-            ) ? '<a href="'
567
-                . $view_txn_url
568
-                . '" title="'
569
-                . esc_attr__('View Transaction', 'event_espresso')
570
-                . '"><span class="reg-pad-rght">'
571
-                . $txn_total
572
-                . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
573
-        } else {
574
-            return '<span class="reg-pad-rght"></span>';
575
-        }
576
-    }
537
+			}
538
+		} else {
539
+			return '<span class="reg-pad-rght"></span>';
540
+		}
541
+	}
542
+
543
+
544
+	/**
545
+	 *        column_TXN_total
546
+	 *
547
+	 * @param \EE_Registration $item
548
+	 * @return string
549
+	 * @throws \EE_Error
550
+	 */
551
+	public function column_TXN_total(EE_Registration $item)
552
+	{
553
+		$txn = $item->transaction();
554
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
555
+		if ($item->get('REG_count') === 1) {
556
+			$line_total_obj = $txn->total_line_item();
557
+			$txn_total = $line_total_obj instanceof EE_Line_Item
558
+				? $line_total_obj->get_pretty('LIN_total')
559
+				: __(
560
+					'View Transaction',
561
+					'event_espresso'
562
+				);
563
+			return EE_Registry::instance()->CAP->current_user_can(
564
+				'ee_read_transaction',
565
+				'espresso_transactions_view_transaction'
566
+			) ? '<a href="'
567
+				. $view_txn_url
568
+				. '" title="'
569
+				. esc_attr__('View Transaction', 'event_espresso')
570
+				. '"><span class="reg-pad-rght">'
571
+				. $txn_total
572
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
573
+		} else {
574
+			return '<span class="reg-pad-rght"></span>';
575
+		}
576
+	}
577 577
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             'TXN_total'           => __('Total', 'event_espresso'),
82 82
         );
83 83
         // Add/remove columns when an event has been selected
84
-        if (! empty($evt_id)) {
84
+        if ( ! empty($evt_id)) {
85 85
             // Render a checkbox column
86 86
             $columns['cb'] = '<input type="checkbox" />';
87 87
             $this->_has_checkbox_column = true;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         }
91 91
         $this->_columns = array_merge($columns, $this->_columns);
92 92
         $this->_primary_column = '_REG_att_checked_in';
93
-        if (! empty($evt_id)
93
+        if ( ! empty($evt_id)
94 94
             && EE_Registry::instance()->CAP->current_user_can(
95 95
                 'ee_read_registrations',
96 96
                 'espresso_registrations_registrations_reports',
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     {
163 163
         $class = parent::_get_row_class($item);
164 164
         // add status class
165
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
165
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
166 166
         if ($this->_has_checkbox_column) {
167 167
             $class .= ' has-checkbox-column';
168 168
         }
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
         if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
182 182
             // this means we don't have an event so let's setup a filter dropdown for all the events to select
183 183
             // note possible capability restrictions
184
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
184
+            if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
185 185
                 $where['status**'] = array('!=', 'private');
186 186
             }
187
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
187
+            if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
188 188
                 $where['EVT_wp_user'] = get_current_user_id();
189 189
             }
190 190
             $events = EEM_Event::instance()->get_all(
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             /** @var EE_Event $evt */
202 202
             foreach ($events as $evt) {
203 203
                 // any registrations for this event?
204
-                if (! $evt->get_count_of_all_registrations()) {
204
+                if ( ! $evt->get_count_of_all_registrations()) {
205 205
                     continue;
206 206
                 }
207 207
                 $evts[] = array(
@@ -220,22 +220,22 @@  discard block
 block discarded – undo
220 220
             $event_filter = '<div class="ee-event-filter">';
221 221
             $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
222 222
             $event_filter .= '<span class="ee-event-filter-toggle">';
223
-            $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
223
+            $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> ';
224 224
             $event_filter .= __('Hide Expired Events', 'event_espresso');
225 225
             $event_filter .= '</span>';
226 226
             $event_filter .= '</div>';
227 227
             $filters[] = $event_filter;
228 228
         }
229
-        if (! empty($this->_dtts_for_event)) {
229
+        if ( ! empty($this->_dtts_for_event)) {
230 230
             // DTT datetimes filter
231 231
             $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
232 232
             if (count($this->_dtts_for_event) > 1) {
233 233
                 $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
234 234
                 foreach ($this->_dtts_for_event as $dtt) {
235 235
                     $datetime_string = $dtt->name();
236
-                    $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
237
-                    $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
238
-                    $dtts[ $dtt->ID() ] = $datetime_string;
236
+                    $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
237
+                    $datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string;
238
+                    $dtts[$dtt->ID()] = $datetime_string;
239 239
                 }
240 240
                 $input = new EE_Select_Input(
241 241
                     $dtts,
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
                     )
247 247
                 );
248 248
                 $filters[] = $input->get_html_for_input();
249
-                $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
249
+                $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">';
250 250
             }
251 251
         }
252 252
         return $filters;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function column__Reg_Status(EE_Registration $item)
292 292
     {
293
-        return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
293
+        return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>';
294 294
     }
295 295
 
296 296
 
@@ -339,11 +339,11 @@  discard block
 block discarded – undo
339 339
                          )
340 340
             ? ' clickable trigger-checkin'
341 341
             : '';
342
-        $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
343
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
344
-               . ' data-_regid="' . $item->ID() . '"'
345
-               . ' data-dttid="' . $this->_cur_dtt_id . '"'
346
-               . ' data-nonce="' . $nonce . '">'
342
+        $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
343
+        return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"'
344
+               . ' data-_regid="'.$item->ID().'"'
345
+               . ' data-dttid="'.$this->_cur_dtt_id.'"'
346
+               . ' data-nonce="'.$nonce.'">'
347 347
                . '</span>'
348 348
                . $mobile_view_content;
349 349
     }
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
     public function column_ATT_name(EE_Registration $item)
358 358
     {
359 359
         $attendee = $item->attendee();
360
-        if (! $attendee instanceof EE_Attendee) {
360
+        if ( ! $attendee instanceof EE_Attendee) {
361 361
             return __('No contact record for this registration.', 'event_espresso');
362 362
         }
363 363
         // edit attendee link
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
             'ee_edit_contacts',
370 370
             'espresso_registrations_edit_attendee'
371 371
         )
372
-            ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
372
+            ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
373 373
               . $item->attendee()->full_name()
374 374
               . '</a>'
375 375
             : $item->attendee()->full_name();
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
             ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
378 378
             : '';
379 379
         // add group details
380
-        $name_link .= '&nbsp;' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
380
+        $name_link .= '&nbsp;'.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
381 381
         // add regcode
382 382
         $link = EE_Admin_Page::add_query_args_and_nonce(
383 383
             array('action' => 'view_registration', '_REG_ID' => $item->ID()),
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
             'view_registration',
390 390
             $item->ID()
391 391
         )
392
-            ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
392
+            ? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
393 393
               . $item->reg_code()
394 394
               . '</a>'
395 395
             : $item->reg_code();
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
         $DTT_ID = $latest_related_datetime instanceof EE_Datetime
406 406
             ? $latest_related_datetime->ID()
407 407
             : $DTT_ID;
408
-        if (! empty($DTT_ID)
408
+        if ( ! empty($DTT_ID)
409 409
             && EE_Registry::instance()->CAP->current_user_can(
410 410
                 'ee_read_checkins',
411 411
                 'espresso_registrations_registration_checkins'
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
             );
418 418
             // get the timestamps for this registration's checkins, related to the selected datetime
419 419
             $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
420
-            if (! empty($timestamps)) {
420
+            if ( ! empty($timestamps)) {
421 421
                 // get the last timestamp
422 422
                 $last_timestamp = end($timestamps);
423 423
                 // checked in or checked out?
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
                     : esc_html__('Checked Out', 'event_espresso');
427 427
                 // get timestamp string
428 428
                 $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
429
-                $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
429
+                $actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'
430 430
                                       . esc_attr__(
431 431
                                           'View this registrant\'s check-ins/checkouts for the datetime',
432 432
                                           'event_espresso'
433
-                                      ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
433
+                                      ).'">'.$checkin_status.': '.$timestamp_string.'</a>';
434 434
             }
435 435
         }
436
-        return (! empty($DTT_ID) && ! empty($timestamps))
436
+        return ( ! empty($DTT_ID) && ! empty($timestamps))
437 437
             ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
438 438
             : $name_link;
439 439
     }
@@ -466,11 +466,11 @@  discard block
 block discarded – undo
466 466
             $event_label = EE_Registry::instance()->CAP->current_user_can(
467 467
                 'ee_read_checkins',
468 468
                 'espresso_registrations_registration_checkins'
469
-            ) ? '<a href="' . $chkin_lnk_url . '" title="'
469
+            ) ? '<a href="'.$chkin_lnk_url.'" title="'
470 470
                 . esc_attr__(
471 471
                     'View Checkins for this Event',
472 472
                     'event_espresso'
473
-                ) . '">' . $event->name() . '</a>' : $event->name();
473
+                ).'">'.$event->name().'</a>' : $event->name();
474 474
         } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
475 475
             $event_label = esc_html__('Unknown', 'event_espresso');
476 476
         }
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
      */
497 497
     public function column__REG_final_price(EE_Registration $item)
498 498
     {
499
-        return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
499
+        return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>';
500 500
     }
501 501
 
502 502
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
                     . $item->transaction()->pretty_paid()
534 534
                     . '
535 535
 					</a>
536
-				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
536
+				<span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
537 537
             }
538 538
         } else {
539 539
             return '<span class="reg-pad-rght"></span>';
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
                 . esc_attr__('View Transaction', 'event_espresso')
570 570
                 . '"><span class="reg-pad-rght">'
571 571
                 . $txn_total
572
-                . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
572
+                . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>';
573 573
         } else {
574 574
             return '<span class="reg-pad-rght"></span>';
575 575
         }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Indentation   +1615 added lines, -1615 removed lines patch added patch discarded remove patch
@@ -15,233 +15,233 @@  discard block
 block discarded – undo
15 15
 class EEH_Activation implements ResettableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * constant used to indicate a cron task is no longer in use
20
-     */
21
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
22
-
23
-    /**
24
-     * WP_User->ID
25
-     *
26
-     * @var int
27
-     */
28
-    private static $_default_creator_id;
29
-
30
-    /**
31
-     * indicates whether or not we've already verified core's default data during this request,
32
-     * because after migrations are done, any addons activated while in maintenance mode
33
-     * will want to setup their own default data, and they might hook into core's default data
34
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
35
-     * This prevents doing that for EVERY single addon.
36
-     *
37
-     * @var boolean
38
-     */
39
-    protected static $_initialized_db_content_already_in_this_request = false;
40
-
41
-    /**
42
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
43
-     */
44
-    private static $table_analysis;
45
-
46
-    /**
47
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
48
-     */
49
-    private static $table_manager;
50
-
51
-
52
-    /**
53
-     * @return \EventEspresso\core\services\database\TableAnalysis
54
-     */
55
-    public static function getTableAnalysis()
56
-    {
57
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59
-        }
60
-        return self::$table_analysis;
61
-    }
62
-
63
-
64
-    /**
65
-     * @return \EventEspresso\core\services\database\TableManager
66
-     */
67
-    public static function getTableManager()
68
-    {
69
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71
-        }
72
-        return self::$table_manager;
73
-    }
74
-
75
-
76
-    /**
77
-     *    _ensure_table_name_has_prefix
78
-     *
79
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
80
-     * @access     public
81
-     * @static
82
-     * @param $table_name
83
-     * @return string
84
-     */
85
-    public static function ensure_table_name_has_prefix($table_name)
86
-    {
87
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
88
-    }
89
-
90
-
91
-    /**
92
-     *    system_initialization
93
-     *    ensures the EE configuration settings are loaded with at least default options set
94
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
95
-     *
96
-     * @access public
97
-     * @static
98
-     * @return void
99
-     */
100
-    public static function system_initialization()
101
-    {
102
-        EEH_Activation::reset_and_update_config();
103
-        // which is fired BEFORE activation of plugin anyways
104
-        EEH_Activation::verify_default_pages_exist();
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets the database schema and creates folders. This should
110
-     * be called on plugin activation and reactivation
111
-     *
112
-     * @return boolean success, whether the database and folders are setup properly
113
-     * @throws \EE_Error
114
-     */
115
-    public static function initialize_db_and_folders()
116
-    {
117
-        return EEH_Activation::create_database_tables();
118
-    }
119
-
120
-
121
-    /**
122
-     * assuming we have an up-to-date database schema, this will populate it
123
-     * with default and initial data. This should be called
124
-     * upon activation of a new plugin, reactivation, and at the end
125
-     * of running migration scripts
126
-     *
127
-     * @throws \EE_Error
128
-     */
129
-    public static function initialize_db_content()
130
-    {
131
-        // let's avoid doing all this logic repeatedly, especially when addons are requesting it
132
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
133
-            return;
134
-        }
135
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
136
-
137
-        EEH_Activation::initialize_system_questions();
138
-        EEH_Activation::insert_default_status_codes();
139
-        EEH_Activation::generate_default_message_templates();
140
-        EEH_Activation::create_no_ticket_prices_array();
141
-        EEH_Activation::removeEmailConfirmFromAddressGroup();
142
-
143
-        EEH_Activation::validate_messages_system();
144
-        EEH_Activation::insert_default_payment_methods();
145
-        // in case we've
146
-        EEH_Activation::remove_cron_tasks();
147
-        EEH_Activation::create_cron_tasks();
148
-        // remove all TXN locks since that is being done via extra meta now
149
-        delete_option('ee_locked_transactions');
150
-        // also, check for CAF default db content
151
-        do_action('AHEE__EEH_Activation__initialize_db_content');
152
-        // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
153
-        // which users really won't care about on initial activation
154
-        EE_Error::overwrite_success();
155
-    }
156
-
157
-
158
-    /**
159
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
160
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
161
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
162
-     * (null)
163
-     *
164
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
165
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
166
-     * @return array
167
-     * @throws \EE_Error
168
-     */
169
-    public static function get_cron_tasks($which_to_include)
170
-    {
171
-        $cron_tasks = apply_filters(
172
-            'FHEE__EEH_Activation__get_cron_tasks',
173
-            array(
174
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
175
-            //              'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
176
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
177
-                // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
178
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
179
-            )
180
-        );
181
-        if ($which_to_include === 'old') {
182
-            $cron_tasks = array_filter(
183
-                $cron_tasks,
184
-                function ($value) {
185
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
186
-                }
187
-            );
188
-        } elseif ($which_to_include === 'current') {
189
-            $cron_tasks = array_filter($cron_tasks);
190
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
191
-            throw new EE_Error(
192
-                sprintf(
193
-                    __(
194
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
195
-                        'event_espresso'
196
-                    ),
197
-                    $which_to_include
198
-                )
199
-            );
200
-        }
201
-        return $cron_tasks;
202
-    }
203
-
204
-
205
-    /**
206
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
207
-     *
208
-     * @throws \EE_Error
209
-     */
210
-    public static function create_cron_tasks()
211
-    {
212
-
213
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
214
-            if (! wp_next_scheduled($hook_name)) {
215
-                /**
216
-                 * This allows client code to define the initial start timestamp for this schedule.
217
-                 */
218
-                if (is_array($frequency)
219
-                    && count($frequency) === 2
220
-                    && isset($frequency[0], $frequency[1])
221
-                ) {
222
-                    $start_timestamp = $frequency[0];
223
-                    $frequency = $frequency[1];
224
-                } else {
225
-                    $start_timestamp = time();
226
-                }
227
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
228
-            }
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     * Remove the currently-existing and now-removed cron tasks.
235
-     *
236
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
237
-     * @throws \EE_Error
238
-     */
239
-    public static function remove_cron_tasks($remove_all = true)
240
-    {
241
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
242
-        $crons                = _get_cron_array();
243
-        $crons                = is_array($crons) ? $crons : array();
244
-        /* reminder of what $crons look like:
18
+	/**
19
+	 * constant used to indicate a cron task is no longer in use
20
+	 */
21
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
22
+
23
+	/**
24
+	 * WP_User->ID
25
+	 *
26
+	 * @var int
27
+	 */
28
+	private static $_default_creator_id;
29
+
30
+	/**
31
+	 * indicates whether or not we've already verified core's default data during this request,
32
+	 * because after migrations are done, any addons activated while in maintenance mode
33
+	 * will want to setup their own default data, and they might hook into core's default data
34
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
35
+	 * This prevents doing that for EVERY single addon.
36
+	 *
37
+	 * @var boolean
38
+	 */
39
+	protected static $_initialized_db_content_already_in_this_request = false;
40
+
41
+	/**
42
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
43
+	 */
44
+	private static $table_analysis;
45
+
46
+	/**
47
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
48
+	 */
49
+	private static $table_manager;
50
+
51
+
52
+	/**
53
+	 * @return \EventEspresso\core\services\database\TableAnalysis
54
+	 */
55
+	public static function getTableAnalysis()
56
+	{
57
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59
+		}
60
+		return self::$table_analysis;
61
+	}
62
+
63
+
64
+	/**
65
+	 * @return \EventEspresso\core\services\database\TableManager
66
+	 */
67
+	public static function getTableManager()
68
+	{
69
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71
+		}
72
+		return self::$table_manager;
73
+	}
74
+
75
+
76
+	/**
77
+	 *    _ensure_table_name_has_prefix
78
+	 *
79
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
80
+	 * @access     public
81
+	 * @static
82
+	 * @param $table_name
83
+	 * @return string
84
+	 */
85
+	public static function ensure_table_name_has_prefix($table_name)
86
+	{
87
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
88
+	}
89
+
90
+
91
+	/**
92
+	 *    system_initialization
93
+	 *    ensures the EE configuration settings are loaded with at least default options set
94
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
95
+	 *
96
+	 * @access public
97
+	 * @static
98
+	 * @return void
99
+	 */
100
+	public static function system_initialization()
101
+	{
102
+		EEH_Activation::reset_and_update_config();
103
+		// which is fired BEFORE activation of plugin anyways
104
+		EEH_Activation::verify_default_pages_exist();
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets the database schema and creates folders. This should
110
+	 * be called on plugin activation and reactivation
111
+	 *
112
+	 * @return boolean success, whether the database and folders are setup properly
113
+	 * @throws \EE_Error
114
+	 */
115
+	public static function initialize_db_and_folders()
116
+	{
117
+		return EEH_Activation::create_database_tables();
118
+	}
119
+
120
+
121
+	/**
122
+	 * assuming we have an up-to-date database schema, this will populate it
123
+	 * with default and initial data. This should be called
124
+	 * upon activation of a new plugin, reactivation, and at the end
125
+	 * of running migration scripts
126
+	 *
127
+	 * @throws \EE_Error
128
+	 */
129
+	public static function initialize_db_content()
130
+	{
131
+		// let's avoid doing all this logic repeatedly, especially when addons are requesting it
132
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
133
+			return;
134
+		}
135
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
136
+
137
+		EEH_Activation::initialize_system_questions();
138
+		EEH_Activation::insert_default_status_codes();
139
+		EEH_Activation::generate_default_message_templates();
140
+		EEH_Activation::create_no_ticket_prices_array();
141
+		EEH_Activation::removeEmailConfirmFromAddressGroup();
142
+
143
+		EEH_Activation::validate_messages_system();
144
+		EEH_Activation::insert_default_payment_methods();
145
+		// in case we've
146
+		EEH_Activation::remove_cron_tasks();
147
+		EEH_Activation::create_cron_tasks();
148
+		// remove all TXN locks since that is being done via extra meta now
149
+		delete_option('ee_locked_transactions');
150
+		// also, check for CAF default db content
151
+		do_action('AHEE__EEH_Activation__initialize_db_content');
152
+		// also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
153
+		// which users really won't care about on initial activation
154
+		EE_Error::overwrite_success();
155
+	}
156
+
157
+
158
+	/**
159
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
160
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
161
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
162
+	 * (null)
163
+	 *
164
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
165
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
166
+	 * @return array
167
+	 * @throws \EE_Error
168
+	 */
169
+	public static function get_cron_tasks($which_to_include)
170
+	{
171
+		$cron_tasks = apply_filters(
172
+			'FHEE__EEH_Activation__get_cron_tasks',
173
+			array(
174
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
175
+			//              'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
176
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
177
+				// there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
178
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
179
+			)
180
+		);
181
+		if ($which_to_include === 'old') {
182
+			$cron_tasks = array_filter(
183
+				$cron_tasks,
184
+				function ($value) {
185
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
186
+				}
187
+			);
188
+		} elseif ($which_to_include === 'current') {
189
+			$cron_tasks = array_filter($cron_tasks);
190
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
191
+			throw new EE_Error(
192
+				sprintf(
193
+					__(
194
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
195
+						'event_espresso'
196
+					),
197
+					$which_to_include
198
+				)
199
+			);
200
+		}
201
+		return $cron_tasks;
202
+	}
203
+
204
+
205
+	/**
206
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
207
+	 *
208
+	 * @throws \EE_Error
209
+	 */
210
+	public static function create_cron_tasks()
211
+	{
212
+
213
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
214
+			if (! wp_next_scheduled($hook_name)) {
215
+				/**
216
+				 * This allows client code to define the initial start timestamp for this schedule.
217
+				 */
218
+				if (is_array($frequency)
219
+					&& count($frequency) === 2
220
+					&& isset($frequency[0], $frequency[1])
221
+				) {
222
+					$start_timestamp = $frequency[0];
223
+					$frequency = $frequency[1];
224
+				} else {
225
+					$start_timestamp = time();
226
+				}
227
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
228
+			}
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 * Remove the currently-existing and now-removed cron tasks.
235
+	 *
236
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
237
+	 * @throws \EE_Error
238
+	 */
239
+	public static function remove_cron_tasks($remove_all = true)
240
+	{
241
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
242
+		$crons                = _get_cron_array();
243
+		$crons                = is_array($crons) ? $crons : array();
244
+		/* reminder of what $crons look like:
245 245
          * Top-level keys are timestamps, and their values are arrays.
246 246
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
247 247
          * and their values are arrays.
@@ -258,925 +258,925 @@  discard block
 block discarded – undo
258 258
          *                  ...
259 259
          *      ...
260 260
          */
261
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
262
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
263
-            if (is_array($hooks_to_fire_at_time)) {
264
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
265
-                    if (isset($ee_cron_tasks_to_remove[ $hook_name ])
266
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
267
-                    ) {
268
-                        unset($crons[ $timestamp ][ $hook_name ]);
269
-                    }
270
-                }
271
-                // also take care of any empty cron timestamps.
272
-                if (empty($hooks_to_fire_at_time)) {
273
-                    unset($crons[ $timestamp ]);
274
-                }
275
-            }
276
-        }
277
-        _set_cron_array($crons);
278
-    }
279
-
280
-
281
-    /**
282
-     *    CPT_initialization
283
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
284
-     *
285
-     * @access public
286
-     * @static
287
-     * @return void
288
-     */
289
-    public static function CPT_initialization()
290
-    {
291
-        // register Custom Post Types
292
-        EE_Registry::instance()->load_core('Register_CPTs');
293
-        flush_rewrite_rules();
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     *    reset_and_update_config
300
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
301
-     * If there is old calendar config data saved, then it will get converted on activation.
302
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
303
-     *
304
-     * @access public
305
-     * @static
306
-     * @return void
307
-     */
308
-    public static function reset_and_update_config()
309
-    {
310
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
311
-        add_filter(
312
-            'FHEE__EE_Config___load_core_config__config_settings',
313
-            array('EEH_Activation', 'migrate_old_config_data'),
314
-            10,
315
-            3
316
-        );
317
-        // EE_Config::reset();
318
-        if (! EE_Config::logging_enabled()) {
319
-            delete_option(EE_Config::LOG_NAME);
320
-        }
321
-    }
322
-
323
-
324
-    /**
325
-     *    load_calendar_config
326
-     *
327
-     * @access    public
328
-     * @return    void
329
-     */
330
-    public static function load_calendar_config()
331
-    {
332
-        // grab array of all plugin folders and loop thru it
333
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
334
-        if (empty($plugins)) {
335
-            return;
336
-        }
337
-        foreach ($plugins as $plugin_path) {
338
-            // grab plugin folder name from path
339
-            $plugin = basename($plugin_path);
340
-            // drill down to Espresso plugins
341
-            // then to calendar related plugins
342
-            if (strpos($plugin, 'espresso') !== false
343
-                || strpos($plugin, 'Espresso') !== false
344
-                || strpos($plugin, 'ee4') !== false
345
-                || strpos($plugin, 'EE4') !== false
346
-                || strpos($plugin, 'calendar') !== false
347
-            ) {
348
-                // this is what we are looking for
349
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
350
-                // does it exist in this folder ?
351
-                if (is_readable($calendar_config)) {
352
-                    // YEAH! let's load it
353
-                    require_once($calendar_config);
354
-                }
355
-            }
356
-        }
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     *    _migrate_old_config_data
363
-     *
364
-     * @access    public
365
-     * @param array|stdClass $settings
366
-     * @param string         $config
367
-     * @param \EE_Config     $EE_Config
368
-     * @return \stdClass
369
-     */
370
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
371
-    {
372
-        $convert_from_array = array('addons');
373
-        // in case old settings were saved as an array
374
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
375
-            // convert existing settings to an object
376
-            $config_array = $settings;
377
-            $settings = new stdClass();
378
-            foreach ($config_array as $key => $value) {
379
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
380
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
381
-                } else {
382
-                    $settings->{$key} = $value;
383
-                }
384
-            }
385
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
386
-        }
387
-        return $settings;
388
-    }
389
-
390
-
391
-    /**
392
-     * deactivate_event_espresso
393
-     *
394
-     * @access public
395
-     * @static
396
-     * @return void
397
-     */
398
-    public static function deactivate_event_espresso()
399
-    {
400
-        // check permissions
401
-        if (current_user_can('activate_plugins')) {
402
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
403
-        }
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * verify_default_pages_exist
410
-     *
411
-     * @access public
412
-     * @static
413
-     * @return void
414
-     * @throws InvalidDataTypeException
415
-     */
416
-    public static function verify_default_pages_exist()
417
-    {
418
-        $critical_page_problem = false;
419
-        $critical_pages = array(
420
-            array(
421
-                'id'   => 'reg_page_id',
422
-                'name' => __('Registration Checkout', 'event_espresso'),
423
-                'post' => null,
424
-                'code' => 'ESPRESSO_CHECKOUT',
425
-            ),
426
-            array(
427
-                'id'   => 'txn_page_id',
428
-                'name' => __('Transactions', 'event_espresso'),
429
-                'post' => null,
430
-                'code' => 'ESPRESSO_TXN_PAGE',
431
-            ),
432
-            array(
433
-                'id'   => 'thank_you_page_id',
434
-                'name' => __('Thank You', 'event_espresso'),
435
-                'post' => null,
436
-                'code' => 'ESPRESSO_THANK_YOU',
437
-            ),
438
-            array(
439
-                'id'   => 'cancel_page_id',
440
-                'name' => __('Registration Cancelled', 'event_espresso'),
441
-                'post' => null,
442
-                'code' => 'ESPRESSO_CANCELLED',
443
-            ),
444
-        );
445
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
446
-        foreach ($critical_pages as $critical_page) {
447
-            // is critical page ID set in config ?
448
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
449
-                // attempt to find post by ID
450
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
451
-            }
452
-            // no dice?
453
-            if ($critical_page['post'] === null) {
454
-                // attempt to find post by title
455
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
456
-                // still nothing?
457
-                if ($critical_page['post'] === null) {
458
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
459
-                    // REALLY? Still nothing ??!?!?
460
-                    if ($critical_page['post'] === null) {
461
-                        $msg = __(
462
-                            'The Event Espresso critical page configuration settings could not be updated.',
463
-                            'event_espresso'
464
-                        );
465
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
466
-                        break;
467
-                    }
468
-                }
469
-            }
470
-            // check that Post ID matches critical page ID in config
471
-            if (isset($critical_page['post']->ID)
472
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
473
-            ) {
474
-                // update Config with post ID
475
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
476
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
477
-                    $msg = __(
478
-                        'The Event Espresso critical page configuration settings could not be updated.',
479
-                        'event_espresso'
480
-                    );
481
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
482
-                }
483
-            }
484
-            $critical_page_problem =
485
-                ! isset($critical_page['post']->post_status)
486
-                || $critical_page['post']->post_status !== 'publish'
487
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
488
-                    ? true
489
-                    : $critical_page_problem;
490
-        }
491
-        if ($critical_page_problem) {
492
-            new PersistentAdminNotice(
493
-                'critical_page_problem',
494
-                sprintf(
495
-                    esc_html__(
496
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
497
-                        'event_espresso'
498
-                    ),
499
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
500
-                    . __('Event Espresso Critical Pages Settings', 'event_espresso')
501
-                    . '</a>'
502
-                )
503
-            );
504
-        }
505
-        if (EE_Error::has_notices()) {
506
-            EE_Error::get_notices(false, true, true);
507
-        }
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * Returns the first post which uses the specified shortcode
514
-     *
515
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
516
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
517
-     *                             "[ESPRESSO_THANK_YOU"
518
-     *                             (we don't search for the closing shortcode bracket because they might have added
519
-     *                             parameter to the shortcode
520
-     * @return WP_Post or NULl
521
-     */
522
-    public static function get_page_by_ee_shortcode($ee_shortcode)
523
-    {
524
-        global $wpdb;
525
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
526
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
527
-        if ($post_id) {
528
-            return get_post($post_id);
529
-        } else {
530
-            return null;
531
-        }
532
-    }
533
-
534
-
535
-    /**
536
-     *    This function generates a post for critical espresso pages
537
-     *
538
-     * @access public
539
-     * @static
540
-     * @param array $critical_page
541
-     * @return array
542
-     */
543
-    public static function create_critical_page($critical_page)
544
-    {
545
-
546
-        $post_args = array(
547
-            'post_title'     => $critical_page['name'],
548
-            'post_status'    => 'publish',
549
-            'post_type'      => 'page',
550
-            'comment_status' => 'closed',
551
-            'post_content'   => '[' . $critical_page['code'] . ']',
552
-        );
553
-
554
-        $post_id = wp_insert_post($post_args);
555
-        if (! $post_id) {
556
-            $msg = sprintf(
557
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
558
-                $critical_page['name']
559
-            );
560
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
561
-            return $critical_page;
562
-        }
563
-        // get newly created post's details
564
-        if (! $critical_page['post'] = get_post($post_id)) {
565
-            $msg = sprintf(
566
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
567
-                $critical_page['name']
568
-            );
569
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
570
-        }
571
-
572
-        return $critical_page;
573
-    }
574
-
575
-
576
-
577
-
578
-    /**
579
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
580
-     * The role being used to check is filterable.
581
-     *
582
-     * @since  4.6.0
583
-     * @global WPDB $wpdb
584
-     * @return mixed null|int WP_user ID or NULL
585
-     */
586
-    public static function get_default_creator_id()
587
-    {
588
-        global $wpdb;
589
-        if (! empty(self::$_default_creator_id)) {
590
-            return self::$_default_creator_id;
591
-        }/**/
592
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
593
-        // let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
594
-        $pre_filtered_id = apply_filters(
595
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
596
-            false,
597
-            $role_to_check
598
-        );
599
-        if ($pre_filtered_id !== false) {
600
-            return (int) $pre_filtered_id;
601
-        }
602
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
603
-        $query = $wpdb->prepare(
604
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
605
-            '%' . $role_to_check . '%'
606
-        );
607
-        $user_id = $wpdb->get_var($query);
608
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
609
-        if ($user_id && (int) $user_id) {
610
-            self::$_default_creator_id = (int) $user_id;
611
-            return self::$_default_creator_id;
612
-        } else {
613
-            return null;
614
-        }
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * used by EE and EE addons during plugin activation to create tables.
621
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
622
-     * but includes extra logic regarding activations.
623
-     *
624
-     * @access public
625
-     * @static
626
-     * @param string  $table_name              without the $wpdb->prefix
627
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
628
-     *                                         table query)
629
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
630
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
631
-     *                                         and new once this function is done (ie, you really do want to CREATE a
632
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
633
-     *                                         you just want to verify the table exists and matches this definition
634
-     *                                         (and if it HAS data in it you want to leave it be)
635
-     * @return void
636
-     * @throws EE_Error if there are database errors
637
-     */
638
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
639
-    {
640
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
641
-            return;
642
-        }
643
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
644
-        if (! function_exists('dbDelta')) {
645
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
646
-        }
647
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
648
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
649
-        // do we need to first delete an existing version of this table ?
650
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
651
-            // ok, delete the table... but ONLY if it's empty
652
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
653
-            // table is NOT empty, are you SURE you want to delete this table ???
654
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
655
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
656
-            } elseif (! $deleted_safely) {
657
-                // so we should be more cautious rather than just dropping tables so easily
658
-                error_log(
659
-                    sprintf(
660
-                        __(
661
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
662
-                            'event_espresso'
663
-                        ),
664
-                        $wp_table_name,
665
-                        '<br/>',
666
-                        'espresso_db_update'
667
-                    )
668
-                );
669
-            }
670
-        }
671
-        $engine = str_replace('ENGINE=', '', $engine);
672
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
673
-    }
674
-
675
-
676
-
677
-    /**
678
-     *    add_column_if_it_doesn't_exist
679
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
680
-     *
681
-     * @access     public
682
-     * @static
683
-     * @deprecated instead use TableManager::addColumn()
684
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
685
-     * @param string $column_name
686
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
687
-     *                            'VARCHAR(10)'
688
-     * @return bool|int
689
-     */
690
-    public static function add_column_if_it_doesnt_exist(
691
-        $table_name,
692
-        $column_name,
693
-        $column_info = 'INT UNSIGNED NOT NULL'
694
-    ) {
695
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
696
-    }
697
-
698
-
699
-    /**
700
-     * get_fields_on_table
701
-     * Gets all the fields on the database table.
702
-     *
703
-     * @access     public
704
-     * @deprecated instead use TableManager::getTableColumns()
705
-     * @static
706
-     * @param string $table_name , without prefixed $wpdb->prefix
707
-     * @return array of database column names
708
-     */
709
-    public static function get_fields_on_table($table_name = null)
710
-    {
711
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
712
-    }
713
-
714
-
715
-    /**
716
-     * db_table_is_empty
717
-     *
718
-     * @access     public\
719
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
720
-     * @static
721
-     * @param string $table_name
722
-     * @return bool
723
-     */
724
-    public static function db_table_is_empty($table_name)
725
-    {
726
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
727
-    }
728
-
729
-
730
-    /**
731
-     * delete_db_table_if_empty
732
-     *
733
-     * @access public
734
-     * @static
735
-     * @param string $table_name
736
-     * @return bool | int
737
-     */
738
-    public static function delete_db_table_if_empty($table_name)
739
-    {
740
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
741
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
742
-        }
743
-        return false;
744
-    }
745
-
746
-
747
-    /**
748
-     * delete_unused_db_table
749
-     *
750
-     * @access     public
751
-     * @static
752
-     * @deprecated instead use TableManager::dropTable()
753
-     * @param string $table_name
754
-     * @return bool | int
755
-     */
756
-    public static function delete_unused_db_table($table_name)
757
-    {
758
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
759
-    }
760
-
761
-
762
-    /**
763
-     * drop_index
764
-     *
765
-     * @access     public
766
-     * @static
767
-     * @deprecated instead use TableManager::dropIndex()
768
-     * @param string $table_name
769
-     * @param string $index_name
770
-     * @return bool | int
771
-     */
772
-    public static function drop_index($table_name, $index_name)
773
-    {
774
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
775
-    }
776
-
777
-
778
-
779
-    /**
780
-     * create_database_tables
781
-     *
782
-     * @access public
783
-     * @static
784
-     * @throws EE_Error
785
-     * @return boolean success (whether database is setup properly or not)
786
-     */
787
-    public static function create_database_tables()
788
-    {
789
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
790
-        // find the migration script that sets the database to be compatible with the code
791
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
792
-        if ($dms_name) {
793
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
794
-            $current_data_migration_script->set_migrating(false);
795
-            $current_data_migration_script->schema_changes_before_migration();
796
-            $current_data_migration_script->schema_changes_after_migration();
797
-            if ($current_data_migration_script->get_errors()) {
798
-                if (WP_DEBUG) {
799
-                    foreach ($current_data_migration_script->get_errors() as $error) {
800
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
801
-                    }
802
-                } else {
803
-                    EE_Error::add_error(
804
-                        __(
805
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
261
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
262
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
263
+			if (is_array($hooks_to_fire_at_time)) {
264
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
265
+					if (isset($ee_cron_tasks_to_remove[ $hook_name ])
266
+						&& is_array($ee_cron_tasks_to_remove[ $hook_name ])
267
+					) {
268
+						unset($crons[ $timestamp ][ $hook_name ]);
269
+					}
270
+				}
271
+				// also take care of any empty cron timestamps.
272
+				if (empty($hooks_to_fire_at_time)) {
273
+					unset($crons[ $timestamp ]);
274
+				}
275
+			}
276
+		}
277
+		_set_cron_array($crons);
278
+	}
279
+
280
+
281
+	/**
282
+	 *    CPT_initialization
283
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
284
+	 *
285
+	 * @access public
286
+	 * @static
287
+	 * @return void
288
+	 */
289
+	public static function CPT_initialization()
290
+	{
291
+		// register Custom Post Types
292
+		EE_Registry::instance()->load_core('Register_CPTs');
293
+		flush_rewrite_rules();
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 *    reset_and_update_config
300
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
301
+	 * If there is old calendar config data saved, then it will get converted on activation.
302
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
303
+	 *
304
+	 * @access public
305
+	 * @static
306
+	 * @return void
307
+	 */
308
+	public static function reset_and_update_config()
309
+	{
310
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
311
+		add_filter(
312
+			'FHEE__EE_Config___load_core_config__config_settings',
313
+			array('EEH_Activation', 'migrate_old_config_data'),
314
+			10,
315
+			3
316
+		);
317
+		// EE_Config::reset();
318
+		if (! EE_Config::logging_enabled()) {
319
+			delete_option(EE_Config::LOG_NAME);
320
+		}
321
+	}
322
+
323
+
324
+	/**
325
+	 *    load_calendar_config
326
+	 *
327
+	 * @access    public
328
+	 * @return    void
329
+	 */
330
+	public static function load_calendar_config()
331
+	{
332
+		// grab array of all plugin folders and loop thru it
333
+		$plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
334
+		if (empty($plugins)) {
335
+			return;
336
+		}
337
+		foreach ($plugins as $plugin_path) {
338
+			// grab plugin folder name from path
339
+			$plugin = basename($plugin_path);
340
+			// drill down to Espresso plugins
341
+			// then to calendar related plugins
342
+			if (strpos($plugin, 'espresso') !== false
343
+				|| strpos($plugin, 'Espresso') !== false
344
+				|| strpos($plugin, 'ee4') !== false
345
+				|| strpos($plugin, 'EE4') !== false
346
+				|| strpos($plugin, 'calendar') !== false
347
+			) {
348
+				// this is what we are looking for
349
+				$calendar_config = $plugin_path . '/EE_Calendar_Config.php';
350
+				// does it exist in this folder ?
351
+				if (is_readable($calendar_config)) {
352
+					// YEAH! let's load it
353
+					require_once($calendar_config);
354
+				}
355
+			}
356
+		}
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 *    _migrate_old_config_data
363
+	 *
364
+	 * @access    public
365
+	 * @param array|stdClass $settings
366
+	 * @param string         $config
367
+	 * @param \EE_Config     $EE_Config
368
+	 * @return \stdClass
369
+	 */
370
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
371
+	{
372
+		$convert_from_array = array('addons');
373
+		// in case old settings were saved as an array
374
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
375
+			// convert existing settings to an object
376
+			$config_array = $settings;
377
+			$settings = new stdClass();
378
+			foreach ($config_array as $key => $value) {
379
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
380
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
381
+				} else {
382
+					$settings->{$key} = $value;
383
+				}
384
+			}
385
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
386
+		}
387
+		return $settings;
388
+	}
389
+
390
+
391
+	/**
392
+	 * deactivate_event_espresso
393
+	 *
394
+	 * @access public
395
+	 * @static
396
+	 * @return void
397
+	 */
398
+	public static function deactivate_event_espresso()
399
+	{
400
+		// check permissions
401
+		if (current_user_can('activate_plugins')) {
402
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
403
+		}
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * verify_default_pages_exist
410
+	 *
411
+	 * @access public
412
+	 * @static
413
+	 * @return void
414
+	 * @throws InvalidDataTypeException
415
+	 */
416
+	public static function verify_default_pages_exist()
417
+	{
418
+		$critical_page_problem = false;
419
+		$critical_pages = array(
420
+			array(
421
+				'id'   => 'reg_page_id',
422
+				'name' => __('Registration Checkout', 'event_espresso'),
423
+				'post' => null,
424
+				'code' => 'ESPRESSO_CHECKOUT',
425
+			),
426
+			array(
427
+				'id'   => 'txn_page_id',
428
+				'name' => __('Transactions', 'event_espresso'),
429
+				'post' => null,
430
+				'code' => 'ESPRESSO_TXN_PAGE',
431
+			),
432
+			array(
433
+				'id'   => 'thank_you_page_id',
434
+				'name' => __('Thank You', 'event_espresso'),
435
+				'post' => null,
436
+				'code' => 'ESPRESSO_THANK_YOU',
437
+			),
438
+			array(
439
+				'id'   => 'cancel_page_id',
440
+				'name' => __('Registration Cancelled', 'event_espresso'),
441
+				'post' => null,
442
+				'code' => 'ESPRESSO_CANCELLED',
443
+			),
444
+		);
445
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
446
+		foreach ($critical_pages as $critical_page) {
447
+			// is critical page ID set in config ?
448
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
449
+				// attempt to find post by ID
450
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
451
+			}
452
+			// no dice?
453
+			if ($critical_page['post'] === null) {
454
+				// attempt to find post by title
455
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
456
+				// still nothing?
457
+				if ($critical_page['post'] === null) {
458
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
459
+					// REALLY? Still nothing ??!?!?
460
+					if ($critical_page['post'] === null) {
461
+						$msg = __(
462
+							'The Event Espresso critical page configuration settings could not be updated.',
463
+							'event_espresso'
464
+						);
465
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
466
+						break;
467
+					}
468
+				}
469
+			}
470
+			// check that Post ID matches critical page ID in config
471
+			if (isset($critical_page['post']->ID)
472
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
473
+			) {
474
+				// update Config with post ID
475
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
476
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
477
+					$msg = __(
478
+						'The Event Espresso critical page configuration settings could not be updated.',
479
+						'event_espresso'
480
+					);
481
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
482
+				}
483
+			}
484
+			$critical_page_problem =
485
+				! isset($critical_page['post']->post_status)
486
+				|| $critical_page['post']->post_status !== 'publish'
487
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
488
+					? true
489
+					: $critical_page_problem;
490
+		}
491
+		if ($critical_page_problem) {
492
+			new PersistentAdminNotice(
493
+				'critical_page_problem',
494
+				sprintf(
495
+					esc_html__(
496
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
497
+						'event_espresso'
498
+					),
499
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
500
+					. __('Event Espresso Critical Pages Settings', 'event_espresso')
501
+					. '</a>'
502
+				)
503
+			);
504
+		}
505
+		if (EE_Error::has_notices()) {
506
+			EE_Error::get_notices(false, true, true);
507
+		}
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * Returns the first post which uses the specified shortcode
514
+	 *
515
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
516
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
517
+	 *                             "[ESPRESSO_THANK_YOU"
518
+	 *                             (we don't search for the closing shortcode bracket because they might have added
519
+	 *                             parameter to the shortcode
520
+	 * @return WP_Post or NULl
521
+	 */
522
+	public static function get_page_by_ee_shortcode($ee_shortcode)
523
+	{
524
+		global $wpdb;
525
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
526
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
527
+		if ($post_id) {
528
+			return get_post($post_id);
529
+		} else {
530
+			return null;
531
+		}
532
+	}
533
+
534
+
535
+	/**
536
+	 *    This function generates a post for critical espresso pages
537
+	 *
538
+	 * @access public
539
+	 * @static
540
+	 * @param array $critical_page
541
+	 * @return array
542
+	 */
543
+	public static function create_critical_page($critical_page)
544
+	{
545
+
546
+		$post_args = array(
547
+			'post_title'     => $critical_page['name'],
548
+			'post_status'    => 'publish',
549
+			'post_type'      => 'page',
550
+			'comment_status' => 'closed',
551
+			'post_content'   => '[' . $critical_page['code'] . ']',
552
+		);
553
+
554
+		$post_id = wp_insert_post($post_args);
555
+		if (! $post_id) {
556
+			$msg = sprintf(
557
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
558
+				$critical_page['name']
559
+			);
560
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
561
+			return $critical_page;
562
+		}
563
+		// get newly created post's details
564
+		if (! $critical_page['post'] = get_post($post_id)) {
565
+			$msg = sprintf(
566
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
567
+				$critical_page['name']
568
+			);
569
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
570
+		}
571
+
572
+		return $critical_page;
573
+	}
574
+
575
+
576
+
577
+
578
+	/**
579
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
580
+	 * The role being used to check is filterable.
581
+	 *
582
+	 * @since  4.6.0
583
+	 * @global WPDB $wpdb
584
+	 * @return mixed null|int WP_user ID or NULL
585
+	 */
586
+	public static function get_default_creator_id()
587
+	{
588
+		global $wpdb;
589
+		if (! empty(self::$_default_creator_id)) {
590
+			return self::$_default_creator_id;
591
+		}/**/
592
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
593
+		// let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
594
+		$pre_filtered_id = apply_filters(
595
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
596
+			false,
597
+			$role_to_check
598
+		);
599
+		if ($pre_filtered_id !== false) {
600
+			return (int) $pre_filtered_id;
601
+		}
602
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
603
+		$query = $wpdb->prepare(
604
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
605
+			'%' . $role_to_check . '%'
606
+		);
607
+		$user_id = $wpdb->get_var($query);
608
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
609
+		if ($user_id && (int) $user_id) {
610
+			self::$_default_creator_id = (int) $user_id;
611
+			return self::$_default_creator_id;
612
+		} else {
613
+			return null;
614
+		}
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * used by EE and EE addons during plugin activation to create tables.
621
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
622
+	 * but includes extra logic regarding activations.
623
+	 *
624
+	 * @access public
625
+	 * @static
626
+	 * @param string  $table_name              without the $wpdb->prefix
627
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
628
+	 *                                         table query)
629
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
630
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
631
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
632
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
633
+	 *                                         you just want to verify the table exists and matches this definition
634
+	 *                                         (and if it HAS data in it you want to leave it be)
635
+	 * @return void
636
+	 * @throws EE_Error if there are database errors
637
+	 */
638
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
639
+	{
640
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
641
+			return;
642
+		}
643
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
644
+		if (! function_exists('dbDelta')) {
645
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
646
+		}
647
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
648
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
649
+		// do we need to first delete an existing version of this table ?
650
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
651
+			// ok, delete the table... but ONLY if it's empty
652
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
653
+			// table is NOT empty, are you SURE you want to delete this table ???
654
+			if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
655
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
656
+			} elseif (! $deleted_safely) {
657
+				// so we should be more cautious rather than just dropping tables so easily
658
+				error_log(
659
+					sprintf(
660
+						__(
661
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
662
+							'event_espresso'
663
+						),
664
+						$wp_table_name,
665
+						'<br/>',
666
+						'espresso_db_update'
667
+					)
668
+				);
669
+			}
670
+		}
671
+		$engine = str_replace('ENGINE=', '', $engine);
672
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
673
+	}
674
+
675
+
676
+
677
+	/**
678
+	 *    add_column_if_it_doesn't_exist
679
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
680
+	 *
681
+	 * @access     public
682
+	 * @static
683
+	 * @deprecated instead use TableManager::addColumn()
684
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
685
+	 * @param string $column_name
686
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
687
+	 *                            'VARCHAR(10)'
688
+	 * @return bool|int
689
+	 */
690
+	public static function add_column_if_it_doesnt_exist(
691
+		$table_name,
692
+		$column_name,
693
+		$column_info = 'INT UNSIGNED NOT NULL'
694
+	) {
695
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
696
+	}
697
+
698
+
699
+	/**
700
+	 * get_fields_on_table
701
+	 * Gets all the fields on the database table.
702
+	 *
703
+	 * @access     public
704
+	 * @deprecated instead use TableManager::getTableColumns()
705
+	 * @static
706
+	 * @param string $table_name , without prefixed $wpdb->prefix
707
+	 * @return array of database column names
708
+	 */
709
+	public static function get_fields_on_table($table_name = null)
710
+	{
711
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
712
+	}
713
+
714
+
715
+	/**
716
+	 * db_table_is_empty
717
+	 *
718
+	 * @access     public\
719
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
720
+	 * @static
721
+	 * @param string $table_name
722
+	 * @return bool
723
+	 */
724
+	public static function db_table_is_empty($table_name)
725
+	{
726
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
727
+	}
728
+
729
+
730
+	/**
731
+	 * delete_db_table_if_empty
732
+	 *
733
+	 * @access public
734
+	 * @static
735
+	 * @param string $table_name
736
+	 * @return bool | int
737
+	 */
738
+	public static function delete_db_table_if_empty($table_name)
739
+	{
740
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
741
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
742
+		}
743
+		return false;
744
+	}
745
+
746
+
747
+	/**
748
+	 * delete_unused_db_table
749
+	 *
750
+	 * @access     public
751
+	 * @static
752
+	 * @deprecated instead use TableManager::dropTable()
753
+	 * @param string $table_name
754
+	 * @return bool | int
755
+	 */
756
+	public static function delete_unused_db_table($table_name)
757
+	{
758
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
759
+	}
760
+
761
+
762
+	/**
763
+	 * drop_index
764
+	 *
765
+	 * @access     public
766
+	 * @static
767
+	 * @deprecated instead use TableManager::dropIndex()
768
+	 * @param string $table_name
769
+	 * @param string $index_name
770
+	 * @return bool | int
771
+	 */
772
+	public static function drop_index($table_name, $index_name)
773
+	{
774
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
775
+	}
776
+
777
+
778
+
779
+	/**
780
+	 * create_database_tables
781
+	 *
782
+	 * @access public
783
+	 * @static
784
+	 * @throws EE_Error
785
+	 * @return boolean success (whether database is setup properly or not)
786
+	 */
787
+	public static function create_database_tables()
788
+	{
789
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
790
+		// find the migration script that sets the database to be compatible with the code
791
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
792
+		if ($dms_name) {
793
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
794
+			$current_data_migration_script->set_migrating(false);
795
+			$current_data_migration_script->schema_changes_before_migration();
796
+			$current_data_migration_script->schema_changes_after_migration();
797
+			if ($current_data_migration_script->get_errors()) {
798
+				if (WP_DEBUG) {
799
+					foreach ($current_data_migration_script->get_errors() as $error) {
800
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
801
+					}
802
+				} else {
803
+					EE_Error::add_error(
804
+						__(
805
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
806 806
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
807
-                            'event_espresso'
808
-                        )
809
-                    );
810
-                }
811
-                return false;
812
-            }
813
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
814
-        } else {
815
-            EE_Error::add_error(
816
-                __(
817
-                    'Could not determine most up-to-date data migration script from which to pull database schema
807
+							'event_espresso'
808
+						)
809
+					);
810
+				}
811
+				return false;
812
+			}
813
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
814
+		} else {
815
+			EE_Error::add_error(
816
+				__(
817
+					'Could not determine most up-to-date data migration script from which to pull database schema
818 818
                      structure. So database is probably not setup properly',
819
-                    'event_espresso'
820
-                ),
821
-                __FILE__,
822
-                __FUNCTION__,
823
-                __LINE__
824
-            );
825
-            return false;
826
-        }
827
-        return true;
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * initialize_system_questions
834
-     *
835
-     * @access public
836
-     * @static
837
-     * @return void
838
-     */
839
-    public static function initialize_system_questions()
840
-    {
841
-        // QUESTION GROUPS
842
-        global $wpdb;
843
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
844
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
845
-        // what we have
846
-        $question_groups = $wpdb->get_col($SQL);
847
-        // check the response
848
-        $question_groups = is_array($question_groups) ? $question_groups : array();
849
-        // what we should have
850
-        $QSG_systems = array(1, 2);
851
-        // loop thru what we should have and compare to what we have
852
-        foreach ($QSG_systems as $QSG_system) {
853
-            // reset values array
854
-            $QSG_values = array();
855
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
856
-            if (! in_array("$QSG_system", $question_groups)) {
857
-                // add it
858
-                switch ($QSG_system) {
859
-                    case 1:
860
-                        $QSG_values = array(
861
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
862
-                            'QSG_identifier'      => 'personal-information-' . time(),
863
-                            'QSG_desc'            => '',
864
-                            'QSG_order'           => 1,
865
-                            'QSG_show_group_name' => 1,
866
-                            'QSG_show_group_desc' => 1,
867
-                            'QSG_system'          => EEM_Question_Group::system_personal,
868
-                            'QSG_deleted'         => 0,
869
-                        );
870
-                        break;
871
-                    case 2:
872
-                        $QSG_values = array(
873
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
874
-                            'QSG_identifier'      => 'address-information-' . time(),
875
-                            'QSG_desc'            => '',
876
-                            'QSG_order'           => 2,
877
-                            'QSG_show_group_name' => 1,
878
-                            'QSG_show_group_desc' => 1,
879
-                            'QSG_system'          => EEM_Question_Group::system_address,
880
-                            'QSG_deleted'         => 0,
881
-                        );
882
-                        break;
883
-                }
884
-                // make sure we have some values before inserting them
885
-                if (! empty($QSG_values)) {
886
-                    // insert system question
887
-                    $wpdb->insert(
888
-                        $table_name,
889
-                        $QSG_values,
890
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
891
-                    );
892
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
893
-                }
894
-            }
895
-        }
896
-        // QUESTIONS
897
-        global $wpdb;
898
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
899
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
900
-        // what we have
901
-        $questions = $wpdb->get_col($SQL);
902
-        // all system questions
903
-        $personal_system_group_questions = ['fname', 'lname', 'email'];
904
-        $address_system_group_questions = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
905
-        $system_questions_not_in_group = ['email_confirm'];
906
-        // merge all of the system questions we should have
907
-        $QST_systems = array_merge(
908
-            $personal_system_group_questions,
909
-            $address_system_group_questions,
910
-            $system_questions_not_in_group
911
-        );
912
-        $order_for_group_1 = 1;
913
-        $order_for_group_2 = 1;
914
-        // loop thru what we should have and compare to what we have
915
-        foreach ($QST_systems as $QST_system) {
916
-            // reset values array
917
-            $QST_values = array();
918
-            // if we don't have what we should have
919
-            if (! in_array($QST_system, $questions)) {
920
-                // add it
921
-                switch ($QST_system) {
922
-                    case 'fname':
923
-                        $QST_values = array(
924
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
925
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
926
-                            'QST_system'        => 'fname',
927
-                            'QST_type'          => 'TEXT',
928
-                            'QST_required'      => 1,
929
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
930
-                            'QST_order'         => 1,
931
-                            'QST_admin_only'    => 0,
932
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
933
-                            'QST_wp_user'       => self::get_default_creator_id(),
934
-                            'QST_deleted'       => 0,
935
-                        );
936
-                        break;
937
-                    case 'lname':
938
-                        $QST_values = array(
939
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
940
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
941
-                            'QST_system'        => 'lname',
942
-                            'QST_type'          => 'TEXT',
943
-                            'QST_required'      => 1,
944
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
945
-                            'QST_order'         => 2,
946
-                            'QST_admin_only'    => 0,
947
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
948
-                            'QST_wp_user'       => self::get_default_creator_id(),
949
-                            'QST_deleted'       => 0,
950
-                        );
951
-                        break;
952
-                    case 'email':
953
-                        $QST_values = array(
954
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
955
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
956
-                            'QST_system'        => 'email',
957
-                            'QST_type'          => 'EMAIL',
958
-                            'QST_required'      => 1,
959
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
960
-                            'QST_order'         => 3,
961
-                            'QST_admin_only'    => 0,
962
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
963
-                            'QST_wp_user'       => self::get_default_creator_id(),
964
-                            'QST_deleted'       => 0,
965
-                        );
966
-                        break;
967
-                    case 'email_confirm':
968
-                        $QST_values = array(
969
-                            'QST_display_text'  => __('Confirm Email Address', 'event_espresso'),
970
-                            'QST_admin_label'   => __('Confirm Email Address - System Question', 'event_espresso'),
971
-                            'QST_system'        => 'email_confirm',
972
-                            'QST_type'          => 'EMAIL_CONFIRM',
973
-                            'QST_required'      => 1,
974
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
975
-                            'QST_order'         => 4,
976
-                            'QST_admin_only'    => 0,
977
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
978
-                            'QST_wp_user'       => self::get_default_creator_id(),
979
-                            'QST_deleted'       => 0,
980
-                        );
981
-                        break;
982
-                    case 'address':
983
-                        $QST_values = array(
984
-                            'QST_display_text'  => __('Address', 'event_espresso'),
985
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
986
-                            'QST_system'        => 'address',
987
-                            'QST_type'          => 'TEXT',
988
-                            'QST_required'      => 0,
989
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
990
-                            'QST_order'         => 5,
991
-                            'QST_admin_only'    => 0,
992
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
993
-                            'QST_wp_user'       => self::get_default_creator_id(),
994
-                            'QST_deleted'       => 0,
995
-                        );
996
-                        break;
997
-                    case 'address2':
998
-                        $QST_values = array(
999
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1000
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1001
-                            'QST_system'        => 'address2',
1002
-                            'QST_type'          => 'TEXT',
1003
-                            'QST_required'      => 0,
1004
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1005
-                            'QST_order'         => 6,
1006
-                            'QST_admin_only'    => 0,
1007
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1008
-                            'QST_wp_user'       => self::get_default_creator_id(),
1009
-                            'QST_deleted'       => 0,
1010
-                        );
1011
-                        break;
1012
-                    case 'city':
1013
-                        $QST_values = array(
1014
-                            'QST_display_text'  => __('City', 'event_espresso'),
1015
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1016
-                            'QST_system'        => 'city',
1017
-                            'QST_type'          => 'TEXT',
1018
-                            'QST_required'      => 0,
1019
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1020
-                            'QST_order'         => 7,
1021
-                            'QST_admin_only'    => 0,
1022
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1023
-                            'QST_wp_user'       => self::get_default_creator_id(),
1024
-                            'QST_deleted'       => 0,
1025
-                        );
1026
-                        break;
1027
-                    case 'country':
1028
-                        $QST_values = array(
1029
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1030
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1031
-                            'QST_system'        => 'country',
1032
-                            'QST_type'          => 'COUNTRY',
1033
-                            'QST_required'      => 0,
1034
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1035
-                            'QST_order'         => 8,
1036
-                            'QST_admin_only'    => 0,
1037
-                            'QST_wp_user'       => self::get_default_creator_id(),
1038
-                            'QST_deleted'       => 0,
1039
-                        );
1040
-                        break;
1041
-                    case 'state':
1042
-                        $QST_values = array(
1043
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1044
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1045
-                            'QST_system'        => 'state',
1046
-                            'QST_type'          => 'STATE',
1047
-                            'QST_required'      => 0,
1048
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1049
-                            'QST_order'         => 9,
1050
-                            'QST_admin_only'    => 0,
1051
-                            'QST_wp_user'       => self::get_default_creator_id(),
1052
-                            'QST_deleted'       => 0,
1053
-                        );
1054
-                        break;
1055
-                    case 'zip':
1056
-                        $QST_values = array(
1057
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1058
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1059
-                            'QST_system'        => 'zip',
1060
-                            'QST_type'          => 'TEXT',
1061
-                            'QST_required'      => 0,
1062
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1063
-                            'QST_order'         => 10,
1064
-                            'QST_admin_only'    => 0,
1065
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1066
-                            'QST_wp_user'       => self::get_default_creator_id(),
1067
-                            'QST_deleted'       => 0,
1068
-                        );
1069
-                        break;
1070
-                    case 'phone':
1071
-                        $QST_values = array(
1072
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1073
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1074
-                            'QST_system'        => 'phone',
1075
-                            'QST_type'          => 'TEXT',
1076
-                            'QST_required'      => 0,
1077
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1078
-                            'QST_order'         => 11,
1079
-                            'QST_admin_only'    => 0,
1080
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1081
-                            'QST_wp_user'       => self::get_default_creator_id(),
1082
-                            'QST_deleted'       => 0,
1083
-                        );
1084
-                        break;
1085
-                }
1086
-                if (! empty($QST_values)) {
1087
-                    // insert system question
1088
-                    $wpdb->insert(
1089
-                        $table_name,
1090
-                        $QST_values,
1091
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1092
-                    );
1093
-                    $QST_ID = $wpdb->insert_id;
1094
-
1095
-                    // QUESTION GROUP QUESTIONS
1096
-                    if (in_array($QST_system, $personal_system_group_questions)) {
1097
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1098
-                    } elseif (in_array($QST_system, $address_system_group_questions)) {
1099
-                        $system_question_we_want = EEM_Question_Group::system_address;
1100
-                    } else {
1101
-                        // QST_system should not be assigned to any group
1102
-                        continue;
1103
-                    }
1104
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1105
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1106
-                    } else {
1107
-                        $id_col = EEM_Question_Group::instance()
1108
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1109
-                        if (is_array($id_col)) {
1110
-                            $QSG_ID = reset($id_col);
1111
-                        } else {
1112
-                            // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1113
-                            EE_Log::instance()->log(
1114
-                                __FILE__,
1115
-                                __FUNCTION__,
1116
-                                sprintf(
1117
-                                    __(
1118
-                                        'Could not associate question %1$s to a question group because no system question
819
+					'event_espresso'
820
+				),
821
+				__FILE__,
822
+				__FUNCTION__,
823
+				__LINE__
824
+			);
825
+			return false;
826
+		}
827
+		return true;
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * initialize_system_questions
834
+	 *
835
+	 * @access public
836
+	 * @static
837
+	 * @return void
838
+	 */
839
+	public static function initialize_system_questions()
840
+	{
841
+		// QUESTION GROUPS
842
+		global $wpdb;
843
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
844
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
845
+		// what we have
846
+		$question_groups = $wpdb->get_col($SQL);
847
+		// check the response
848
+		$question_groups = is_array($question_groups) ? $question_groups : array();
849
+		// what we should have
850
+		$QSG_systems = array(1, 2);
851
+		// loop thru what we should have and compare to what we have
852
+		foreach ($QSG_systems as $QSG_system) {
853
+			// reset values array
854
+			$QSG_values = array();
855
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
856
+			if (! in_array("$QSG_system", $question_groups)) {
857
+				// add it
858
+				switch ($QSG_system) {
859
+					case 1:
860
+						$QSG_values = array(
861
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
862
+							'QSG_identifier'      => 'personal-information-' . time(),
863
+							'QSG_desc'            => '',
864
+							'QSG_order'           => 1,
865
+							'QSG_show_group_name' => 1,
866
+							'QSG_show_group_desc' => 1,
867
+							'QSG_system'          => EEM_Question_Group::system_personal,
868
+							'QSG_deleted'         => 0,
869
+						);
870
+						break;
871
+					case 2:
872
+						$QSG_values = array(
873
+							'QSG_name'            => __('Address Information', 'event_espresso'),
874
+							'QSG_identifier'      => 'address-information-' . time(),
875
+							'QSG_desc'            => '',
876
+							'QSG_order'           => 2,
877
+							'QSG_show_group_name' => 1,
878
+							'QSG_show_group_desc' => 1,
879
+							'QSG_system'          => EEM_Question_Group::system_address,
880
+							'QSG_deleted'         => 0,
881
+						);
882
+						break;
883
+				}
884
+				// make sure we have some values before inserting them
885
+				if (! empty($QSG_values)) {
886
+					// insert system question
887
+					$wpdb->insert(
888
+						$table_name,
889
+						$QSG_values,
890
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
891
+					);
892
+					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
893
+				}
894
+			}
895
+		}
896
+		// QUESTIONS
897
+		global $wpdb;
898
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
899
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
900
+		// what we have
901
+		$questions = $wpdb->get_col($SQL);
902
+		// all system questions
903
+		$personal_system_group_questions = ['fname', 'lname', 'email'];
904
+		$address_system_group_questions = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone'];
905
+		$system_questions_not_in_group = ['email_confirm'];
906
+		// merge all of the system questions we should have
907
+		$QST_systems = array_merge(
908
+			$personal_system_group_questions,
909
+			$address_system_group_questions,
910
+			$system_questions_not_in_group
911
+		);
912
+		$order_for_group_1 = 1;
913
+		$order_for_group_2 = 1;
914
+		// loop thru what we should have and compare to what we have
915
+		foreach ($QST_systems as $QST_system) {
916
+			// reset values array
917
+			$QST_values = array();
918
+			// if we don't have what we should have
919
+			if (! in_array($QST_system, $questions)) {
920
+				// add it
921
+				switch ($QST_system) {
922
+					case 'fname':
923
+						$QST_values = array(
924
+							'QST_display_text'  => __('First Name', 'event_espresso'),
925
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
926
+							'QST_system'        => 'fname',
927
+							'QST_type'          => 'TEXT',
928
+							'QST_required'      => 1,
929
+							'QST_required_text' => __('This field is required', 'event_espresso'),
930
+							'QST_order'         => 1,
931
+							'QST_admin_only'    => 0,
932
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
933
+							'QST_wp_user'       => self::get_default_creator_id(),
934
+							'QST_deleted'       => 0,
935
+						);
936
+						break;
937
+					case 'lname':
938
+						$QST_values = array(
939
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
940
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
941
+							'QST_system'        => 'lname',
942
+							'QST_type'          => 'TEXT',
943
+							'QST_required'      => 1,
944
+							'QST_required_text' => __('This field is required', 'event_espresso'),
945
+							'QST_order'         => 2,
946
+							'QST_admin_only'    => 0,
947
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
948
+							'QST_wp_user'       => self::get_default_creator_id(),
949
+							'QST_deleted'       => 0,
950
+						);
951
+						break;
952
+					case 'email':
953
+						$QST_values = array(
954
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
955
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
956
+							'QST_system'        => 'email',
957
+							'QST_type'          => 'EMAIL',
958
+							'QST_required'      => 1,
959
+							'QST_required_text' => __('This field is required', 'event_espresso'),
960
+							'QST_order'         => 3,
961
+							'QST_admin_only'    => 0,
962
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
963
+							'QST_wp_user'       => self::get_default_creator_id(),
964
+							'QST_deleted'       => 0,
965
+						);
966
+						break;
967
+					case 'email_confirm':
968
+						$QST_values = array(
969
+							'QST_display_text'  => __('Confirm Email Address', 'event_espresso'),
970
+							'QST_admin_label'   => __('Confirm Email Address - System Question', 'event_espresso'),
971
+							'QST_system'        => 'email_confirm',
972
+							'QST_type'          => 'EMAIL_CONFIRM',
973
+							'QST_required'      => 1,
974
+							'QST_required_text' => __('This field is required', 'event_espresso'),
975
+							'QST_order'         => 4,
976
+							'QST_admin_only'    => 0,
977
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
978
+							'QST_wp_user'       => self::get_default_creator_id(),
979
+							'QST_deleted'       => 0,
980
+						);
981
+						break;
982
+					case 'address':
983
+						$QST_values = array(
984
+							'QST_display_text'  => __('Address', 'event_espresso'),
985
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
986
+							'QST_system'        => 'address',
987
+							'QST_type'          => 'TEXT',
988
+							'QST_required'      => 0,
989
+							'QST_required_text' => __('This field is required', 'event_espresso'),
990
+							'QST_order'         => 5,
991
+							'QST_admin_only'    => 0,
992
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
993
+							'QST_wp_user'       => self::get_default_creator_id(),
994
+							'QST_deleted'       => 0,
995
+						);
996
+						break;
997
+					case 'address2':
998
+						$QST_values = array(
999
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1000
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1001
+							'QST_system'        => 'address2',
1002
+							'QST_type'          => 'TEXT',
1003
+							'QST_required'      => 0,
1004
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1005
+							'QST_order'         => 6,
1006
+							'QST_admin_only'    => 0,
1007
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1008
+							'QST_wp_user'       => self::get_default_creator_id(),
1009
+							'QST_deleted'       => 0,
1010
+						);
1011
+						break;
1012
+					case 'city':
1013
+						$QST_values = array(
1014
+							'QST_display_text'  => __('City', 'event_espresso'),
1015
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1016
+							'QST_system'        => 'city',
1017
+							'QST_type'          => 'TEXT',
1018
+							'QST_required'      => 0,
1019
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1020
+							'QST_order'         => 7,
1021
+							'QST_admin_only'    => 0,
1022
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1023
+							'QST_wp_user'       => self::get_default_creator_id(),
1024
+							'QST_deleted'       => 0,
1025
+						);
1026
+						break;
1027
+					case 'country':
1028
+						$QST_values = array(
1029
+							'QST_display_text'  => __('Country', 'event_espresso'),
1030
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1031
+							'QST_system'        => 'country',
1032
+							'QST_type'          => 'COUNTRY',
1033
+							'QST_required'      => 0,
1034
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1035
+							'QST_order'         => 8,
1036
+							'QST_admin_only'    => 0,
1037
+							'QST_wp_user'       => self::get_default_creator_id(),
1038
+							'QST_deleted'       => 0,
1039
+						);
1040
+						break;
1041
+					case 'state':
1042
+						$QST_values = array(
1043
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1044
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1045
+							'QST_system'        => 'state',
1046
+							'QST_type'          => 'STATE',
1047
+							'QST_required'      => 0,
1048
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1049
+							'QST_order'         => 9,
1050
+							'QST_admin_only'    => 0,
1051
+							'QST_wp_user'       => self::get_default_creator_id(),
1052
+							'QST_deleted'       => 0,
1053
+						);
1054
+						break;
1055
+					case 'zip':
1056
+						$QST_values = array(
1057
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1058
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1059
+							'QST_system'        => 'zip',
1060
+							'QST_type'          => 'TEXT',
1061
+							'QST_required'      => 0,
1062
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1063
+							'QST_order'         => 10,
1064
+							'QST_admin_only'    => 0,
1065
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1066
+							'QST_wp_user'       => self::get_default_creator_id(),
1067
+							'QST_deleted'       => 0,
1068
+						);
1069
+						break;
1070
+					case 'phone':
1071
+						$QST_values = array(
1072
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1073
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1074
+							'QST_system'        => 'phone',
1075
+							'QST_type'          => 'TEXT',
1076
+							'QST_required'      => 0,
1077
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1078
+							'QST_order'         => 11,
1079
+							'QST_admin_only'    => 0,
1080
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1081
+							'QST_wp_user'       => self::get_default_creator_id(),
1082
+							'QST_deleted'       => 0,
1083
+						);
1084
+						break;
1085
+				}
1086
+				if (! empty($QST_values)) {
1087
+					// insert system question
1088
+					$wpdb->insert(
1089
+						$table_name,
1090
+						$QST_values,
1091
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1092
+					);
1093
+					$QST_ID = $wpdb->insert_id;
1094
+
1095
+					// QUESTION GROUP QUESTIONS
1096
+					if (in_array($QST_system, $personal_system_group_questions)) {
1097
+						$system_question_we_want = EEM_Question_Group::system_personal;
1098
+					} elseif (in_array($QST_system, $address_system_group_questions)) {
1099
+						$system_question_we_want = EEM_Question_Group::system_address;
1100
+					} else {
1101
+						// QST_system should not be assigned to any group
1102
+						continue;
1103
+					}
1104
+					if (isset($QSG_IDs[ $system_question_we_want ])) {
1105
+						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1106
+					} else {
1107
+						$id_col = EEM_Question_Group::instance()
1108
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1109
+						if (is_array($id_col)) {
1110
+							$QSG_ID = reset($id_col);
1111
+						} else {
1112
+							// ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1113
+							EE_Log::instance()->log(
1114
+								__FILE__,
1115
+								__FUNCTION__,
1116
+								sprintf(
1117
+									__(
1118
+										'Could not associate question %1$s to a question group because no system question
1119 1119
                                          group existed',
1120
-                                        'event_espresso'
1121
-                                    ),
1122
-                                    $QST_ID
1123
-                                ),
1124
-                                'error'
1125
-                            );
1126
-                            continue;
1127
-                        }
1128
-                    }
1129
-                    // add system questions to groups
1130
-                    $wpdb->insert(
1131
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1132
-                        array(
1133
-                            'QSG_ID'    => $QSG_ID,
1134
-                            'QST_ID'    => $QST_ID,
1135
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1136
-                        ),
1137
-                        array('%d', '%d', '%d')
1138
-                    );
1139
-                }
1140
-            }
1141
-        }
1142
-    }
1143
-
1144
-
1145
-    /**
1146
-     * Makes sure the default payment method (Invoice) is active.
1147
-     * This used to be done automatically as part of constructing the old gateways config
1148
-     *
1149
-     * @throws \EE_Error
1150
-     */
1151
-    public static function insert_default_payment_methods()
1152
-    {
1153
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1154
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1155
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1156
-        } else {
1157
-            EEM_Payment_Method::instance()->verify_button_urls();
1158
-        }
1159
-    }
1160
-
1161
-    /**
1162
-     * insert_default_status_codes
1163
-     *
1164
-     * @access public
1165
-     * @static
1166
-     * @return void
1167
-     */
1168
-    public static function insert_default_status_codes()
1169
-    {
1170
-
1171
-        global $wpdb;
1172
-
1173
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1174
-            $table_name = EEM_Status::instance()->table();
1175
-
1176
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1177
-            $wpdb->query($SQL);
1178
-
1179
-            $SQL = "INSERT INTO $table_name
1120
+										'event_espresso'
1121
+									),
1122
+									$QST_ID
1123
+								),
1124
+								'error'
1125
+							);
1126
+							continue;
1127
+						}
1128
+					}
1129
+					// add system questions to groups
1130
+					$wpdb->insert(
1131
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1132
+						array(
1133
+							'QSG_ID'    => $QSG_ID,
1134
+							'QST_ID'    => $QST_ID,
1135
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1136
+						),
1137
+						array('%d', '%d', '%d')
1138
+					);
1139
+				}
1140
+			}
1141
+		}
1142
+	}
1143
+
1144
+
1145
+	/**
1146
+	 * Makes sure the default payment method (Invoice) is active.
1147
+	 * This used to be done automatically as part of constructing the old gateways config
1148
+	 *
1149
+	 * @throws \EE_Error
1150
+	 */
1151
+	public static function insert_default_payment_methods()
1152
+	{
1153
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1154
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1155
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1156
+		} else {
1157
+			EEM_Payment_Method::instance()->verify_button_urls();
1158
+		}
1159
+	}
1160
+
1161
+	/**
1162
+	 * insert_default_status_codes
1163
+	 *
1164
+	 * @access public
1165
+	 * @static
1166
+	 * @return void
1167
+	 */
1168
+	public static function insert_default_status_codes()
1169
+	{
1170
+
1171
+		global $wpdb;
1172
+
1173
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1174
+			$table_name = EEM_Status::instance()->table();
1175
+
1176
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1177
+			$wpdb->query($SQL);
1178
+
1179
+			$SQL = "INSERT INTO $table_name
1180 1180
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1181 1181
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1182 1182
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1216,479 +1216,479 @@  discard block
 block discarded – undo
1216 1216
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1217 1217
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1218 1218
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1219
-            $wpdb->query($SQL);
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * generate_default_message_templates
1226
-     *
1227
-     * @static
1228
-     * @throws EE_Error
1229
-     * @return bool     true means new templates were created.
1230
-     *                  false means no templates were created.
1231
-     *                  This is NOT an error flag. To check for errors you will want
1232
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1233
-     */
1234
-    public static function generate_default_message_templates()
1235
-    {
1236
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1237
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1238
-        /*
1219
+			$wpdb->query($SQL);
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * generate_default_message_templates
1226
+	 *
1227
+	 * @static
1228
+	 * @throws EE_Error
1229
+	 * @return bool     true means new templates were created.
1230
+	 *                  false means no templates were created.
1231
+	 *                  This is NOT an error flag. To check for errors you will want
1232
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1233
+	 */
1234
+	public static function generate_default_message_templates()
1235
+	{
1236
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1237
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1238
+		/*
1239 1239
          * This first method is taking care of ensuring any default messengers
1240 1240
          * that should be made active and have templates generated are done.
1241 1241
          */
1242
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1243
-            $message_resource_manager
1244
-        );
1245
-        /**
1246
-         * This method is verifying there are no NEW default message types
1247
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1248
-         */
1249
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1250
-            $message_resource_manager
1251
-        );
1252
-        // after all is done, let's persist these changes to the db.
1253
-        $message_resource_manager->update_has_activated_messengers_option();
1254
-        $message_resource_manager->update_active_messengers_option();
1255
-        // will return true if either of these are true.  Otherwise will return false.
1256
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1257
-    }
1258
-
1259
-
1260
-
1261
-    /**
1262
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1263
-     * @return array|bool
1264
-     * @throws \EE_Error
1265
-     */
1266
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1267
-        EE_Message_Resource_Manager $message_resource_manager
1268
-    ) {
1269
-        /** @type EE_messenger[] $active_messengers */
1270
-        $active_messengers = $message_resource_manager->active_messengers();
1271
-        $installed_message_types = $message_resource_manager->installed_message_types();
1272
-        $templates_created = false;
1273
-        foreach ($active_messengers as $active_messenger) {
1274
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1275
-            $default_message_type_names_to_activate = array();
1276
-            // looping through each default message type reported by the messenger
1277
-            // and setup the actual message types to activate.
1278
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1279
-                // if already active or has already been activated before we skip
1280
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1281
-                // we also skip if the message type is not installed.
1282
-                if ($message_resource_manager->has_message_type_been_activated_for_messenger(
1283
-                    $default_message_type_name_for_messenger,
1284
-                    $active_messenger->name
1285
-                )
1286
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1287
-                        $active_messenger->name,
1288
-                        $default_message_type_name_for_messenger
1289
-                    )
1290
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1291
-                ) {
1292
-                    continue;
1293
-                }
1294
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1295
-            }
1296
-            // let's activate!
1297
-            $message_resource_manager->ensure_message_types_are_active(
1298
-                $default_message_type_names_to_activate,
1299
-                $active_messenger->name,
1300
-                false
1301
-            );
1302
-            // activate the templates for these message types
1303
-            if (! empty($default_message_type_names_to_activate)) {
1304
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1305
-                    $active_messenger->name,
1306
-                    $default_message_type_names_for_messenger,
1307
-                    '',
1308
-                    true
1309
-                );
1310
-            }
1311
-        }
1312
-        return $templates_created;
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     * This will activate and generate default messengers and default message types for those messengers.
1319
-     *
1320
-     * @param EE_message_Resource_Manager $message_resource_manager
1321
-     * @return array|bool  True means there were default messengers and message type templates generated.
1322
-     *                     False means that there were no templates generated
1323
-     *                     (which could simply mean there are no default message types for a messenger).
1324
-     * @throws EE_Error
1325
-     */
1326
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1327
-        EE_Message_Resource_Manager $message_resource_manager
1328
-    ) {
1329
-        /** @type EE_messenger[] $messengers_to_generate */
1330
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1331
-        $installed_message_types = $message_resource_manager->installed_message_types();
1332
-        $templates_generated = false;
1333
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1334
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1335
-            // verify the default message types match an installed message type.
1336
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1337
-                if (! isset($installed_message_types[ $name ])
1338
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1339
-                        $name,
1340
-                        $messenger_to_generate->name
1341
-                    )
1342
-                ) {
1343
-                    unset($default_message_type_names_for_messenger[ $key ]);
1344
-                }
1345
-            }
1346
-            // in previous iterations, the active_messengers option in the db
1347
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1348
-            // This comment is left here just in case we discover that we _do_ need to update before
1349
-            // passing off to create templates (after the refactor is done).
1350
-            // @todo remove this comment when determined not necessary.
1351
-            $message_resource_manager->activate_messenger(
1352
-                $messenger_to_generate->name,
1353
-                $default_message_type_names_for_messenger,
1354
-                false
1355
-            );
1356
-            // create any templates needing created (or will reactivate templates already generated as necessary).
1357
-            if (! empty($default_message_type_names_for_messenger)) {
1358
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1359
-                    $messenger_to_generate->name,
1360
-                    $default_message_type_names_for_messenger,
1361
-                    '',
1362
-                    true
1363
-                );
1364
-            }
1365
-        }
1366
-        return $templates_generated;
1367
-    }
1368
-
1369
-
1370
-    /**
1371
-     * This returns the default messengers to generate templates for on activation of EE.
1372
-     * It considers:
1373
-     * - whether a messenger is already active in the db.
1374
-     * - whether a messenger has been made active at any time in the past.
1375
-     *
1376
-     * @static
1377
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1378
-     * @return EE_messenger[]
1379
-     */
1380
-    protected static function _get_default_messengers_to_generate_on_activation(
1381
-        EE_Message_Resource_Manager $message_resource_manager
1382
-    ) {
1383
-        $active_messengers    = $message_resource_manager->active_messengers();
1384
-        $installed_messengers = $message_resource_manager->installed_messengers();
1385
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1386
-
1387
-        $messengers_to_generate = array();
1388
-        foreach ($installed_messengers as $installed_messenger) {
1389
-            // if installed messenger is a messenger that should be activated on install
1390
-            // and is not already active
1391
-            // and has never been activated
1392
-            if (! $installed_messenger->activate_on_install
1393
-                || isset($active_messengers[ $installed_messenger->name ])
1394
-                || isset($has_activated[ $installed_messenger->name ])
1395
-            ) {
1396
-                continue;
1397
-            }
1398
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1399
-        }
1400
-        return $messengers_to_generate;
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * This simply validates active message types to ensure they actually match installed
1406
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1407
-     * rows are set inactive.
1408
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1409
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1410
-     * are still handled in here.
1411
-     *
1412
-     * @since 4.3.1
1413
-     * @return void
1414
-     */
1415
-    public static function validate_messages_system()
1416
-    {
1417
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1418
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1419
-        $message_resource_manager->validate_active_message_types_are_installed();
1420
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1421
-    }
1422
-
1423
-
1424
-    /**
1425
-     * create_no_ticket_prices_array
1426
-     *
1427
-     * @access public
1428
-     * @static
1429
-     * @return void
1430
-     */
1431
-    public static function create_no_ticket_prices_array()
1432
-    {
1433
-        // this creates an array for tracking events that have no active ticket prices created
1434
-        // this allows us to warn admins of the situation so that it can be corrected
1435
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1436
-        if (! $espresso_no_ticket_prices) {
1437
-            add_option('ee_no_ticket_prices', array(), '', false);
1438
-        }
1439
-    }
1440
-
1441
-
1442
-    /**
1443
-     * plugin_deactivation
1444
-     *
1445
-     * @access public
1446
-     * @static
1447
-     * @return void
1448
-     */
1449
-    public static function plugin_deactivation()
1450
-    {
1451
-    }
1452
-
1453
-
1454
-    /**
1455
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1456
-     * (like post meta or term relations)
1457
-     *
1458
-     * @global wpdb $wpdb
1459
-     * @throws \EE_Error
1460
-     */
1461
-    public static function delete_all_espresso_cpt_data()
1462
-    {
1463
-        global $wpdb;
1464
-        // get all the CPT post_types
1465
-        $ee_post_types = array();
1466
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1467
-            if (method_exists($model_name, 'instance')) {
1468
-                $model_obj = call_user_func(array($model_name, 'instance'));
1469
-                if ($model_obj instanceof EEM_CPT_Base) {
1470
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1471
-                }
1472
-            }
1473
-        }
1474
-        // get all our CPTs
1475
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1476
-        $cpt_ids = $wpdb->get_col($query);
1477
-        // delete each post meta and term relations too
1478
-        foreach ($cpt_ids as $post_id) {
1479
-            wp_delete_post($post_id, true);
1480
-        }
1481
-    }
1482
-
1483
-    /**
1484
-     * Deletes all EE custom tables
1485
-     *
1486
-     * @return array
1487
-     */
1488
-    public static function drop_espresso_tables()
1489
-    {
1490
-        $tables = array();
1491
-        // load registry
1492
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1493
-            if (method_exists($model_name, 'instance')) {
1494
-                $model_obj = call_user_func(array($model_name, 'instance'));
1495
-                if ($model_obj instanceof EEM_Base) {
1496
-                    foreach ($model_obj->get_tables() as $table) {
1497
-                        if (strpos($table->get_table_name(), 'esp_')
1498
-                            &&
1499
-                            (
1500
-                                is_main_site()// main site? nuke them all
1501
-                                || ! $table->is_global()// not main site,but not global either. nuke it
1502
-                            )
1503
-                        ) {
1504
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1505
-                        }
1506
-                    }
1507
-                }
1508
-            }
1509
-        }
1510
-
1511
-        // there are some tables whose models were removed.
1512
-        // they should be removed when removing all EE core's data
1513
-        $tables_without_models = array(
1514
-            'esp_promotion',
1515
-            'esp_promotion_applied',
1516
-            'esp_promotion_object',
1517
-            'esp_promotion_rule',
1518
-            'esp_rule',
1519
-        );
1520
-        foreach ($tables_without_models as $table) {
1521
-            $tables[ $table ] = $table;
1522
-        }
1523
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1524
-    }
1525
-
1526
-
1527
-
1528
-    /**
1529
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1530
-     * each table name provided has a wpdb prefix attached, and that it exists.
1531
-     * Returns the list actually deleted
1532
-     *
1533
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1534
-     * @global WPDB $wpdb
1535
-     * @param array $table_names
1536
-     * @return array of table names which we deleted
1537
-     */
1538
-    public static function drop_tables($table_names)
1539
-    {
1540
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1541
-    }
1542
-
1543
-
1544
-
1545
-    /**
1546
-     * plugin_uninstall
1547
-     *
1548
-     * @access public
1549
-     * @static
1550
-     * @param bool $remove_all
1551
-     * @return void
1552
-     */
1553
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1554
-    {
1555
-        global $wpdb;
1556
-        self::drop_espresso_tables();
1557
-        $wp_options_to_delete = array(
1558
-            'ee_no_ticket_prices'                => true,
1559
-            'ee_active_messengers'               => true,
1560
-            'ee_has_activated_messenger'         => true,
1561
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1562
-            'ee_config'                          => false,
1563
-            'ee_data_migration_current_db_state' => true,
1564
-            'ee_data_migration_mapping_'         => false,
1565
-            'ee_data_migration_script_'          => false,
1566
-            'ee_data_migrations'                 => true,
1567
-            'ee_dms_map'                         => false,
1568
-            'ee_notices'                         => true,
1569
-            'lang_file_check_'                   => false,
1570
-            'ee_maintenance_mode'                => true,
1571
-            'ee_ueip_optin'                      => true,
1572
-            'ee_ueip_has_notified'               => true,
1573
-            'ee_plugin_activation_errors'        => true,
1574
-            'ee_id_mapping_from'                 => false,
1575
-            'espresso_persistent_admin_notices'  => true,
1576
-            'ee_encryption_key'                  => true,
1577
-            'pue_force_upgrade_'                 => false,
1578
-            'pue_json_error_'                    => false,
1579
-            'pue_install_key_'                   => false,
1580
-            'pue_verification_error_'            => false,
1581
-            'pu_dismissed_upgrade_'              => false,
1582
-            'external_updates-'                  => false,
1583
-            'ee_extra_data'                      => true,
1584
-            'ee_ssn_'                            => false,
1585
-            'ee_rss_'                            => false,
1586
-            'ee_rte_n_tx_'                       => false,
1587
-            'ee_pers_admin_notices'              => true,
1588
-            'ee_job_parameters_'                 => false,
1589
-            'ee_upload_directories_incomplete'   => true,
1590
-            'ee_verified_db_collations'          => true,
1591
-        );
1592
-        if (is_main_site()) {
1593
-            $wp_options_to_delete['ee_network_config'] = true;
1594
-        }
1595
-        $undeleted_options = array();
1596
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1597
-            if ($no_wildcard) {
1598
-                if (! delete_option($option_name)) {
1599
-                    $undeleted_options[] = $option_name;
1600
-                }
1601
-            } else {
1602
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1603
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1604
-                    if (! delete_option($option_name_from_wildcard)) {
1605
-                        $undeleted_options[] = $option_name_from_wildcard;
1606
-                    }
1607
-                }
1608
-            }
1609
-        }
1610
-        // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1611
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1612
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1613
-            $db_update_sans_ee4 = array();
1614
-            foreach ($espresso_db_update as $version => $times_activated) {
1615
-                if ((string) $version[0] === '3') {// if its NON EE4
1616
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1617
-                }
1618
-            }
1619
-            update_option('espresso_db_update', $db_update_sans_ee4);
1620
-        }
1621
-        $errors = '';
1622
-        if (! empty($undeleted_options)) {
1623
-            $errors .= sprintf(
1624
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1625
-                '<br/>',
1626
-                implode(',<br/>', $undeleted_options)
1627
-            );
1628
-        }
1629
-        if (! empty($errors)) {
1630
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1631
-        }
1632
-    }
1633
-
1634
-    /**
1635
-     * Gets the mysql error code from the last used query by wpdb
1636
-     *
1637
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1638
-     */
1639
-    public static function last_wpdb_error_code()
1640
-    {
1641
-        // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved
1642
-        global $wpdb;
1643
-        if ($wpdb->use_mysqli) {
1644
-            return mysqli_errno($wpdb->dbh);
1645
-        } else {
1646
-            return mysql_errno($wpdb->dbh);
1647
-        }
1648
-        // phpcs:enable
1649
-    }
1650
-
1651
-    /**
1652
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1653
-     *
1654
-     * @global wpdb  $wpdb
1655
-     * @deprecated instead use TableAnalysis::tableExists()
1656
-     * @param string $table_name with or without $wpdb->prefix
1657
-     * @return boolean
1658
-     */
1659
-    public static function table_exists($table_name)
1660
-    {
1661
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1662
-    }
1663
-
1664
-    /**
1665
-     * Resets the cache on EEH_Activation
1666
-     */
1667
-    public static function reset()
1668
-    {
1669
-        self::$_default_creator_id                             = null;
1670
-        self::$_initialized_db_content_already_in_this_request = false;
1671
-    }
1672
-
1673
-    /**
1674
-     * Removes 'email_confirm' from the Address info question group on activation
1675
-     * @return void
1676
-     */
1677
-    public static function removeEmailConfirmFromAddressGroup()
1678
-    {
1679
-
1680
-        // Pull the email_confirm question ID.
1681
-        $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1682
-            EEM_Attendee::system_question_email_confirm
1683
-        );
1684
-        // Remove the email_confirm question group from the address group questions.
1685
-        EEM_Question_Group_Question::instance()->delete(
1686
-            array(
1687
-                array(
1688
-                    'QST_ID' => $email_confirm_question_id,
1689
-                    'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1690
-                ),
1691
-            )
1692
-        );
1693
-    }
1242
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1243
+			$message_resource_manager
1244
+		);
1245
+		/**
1246
+		 * This method is verifying there are no NEW default message types
1247
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1248
+		 */
1249
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1250
+			$message_resource_manager
1251
+		);
1252
+		// after all is done, let's persist these changes to the db.
1253
+		$message_resource_manager->update_has_activated_messengers_option();
1254
+		$message_resource_manager->update_active_messengers_option();
1255
+		// will return true if either of these are true.  Otherwise will return false.
1256
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1257
+	}
1258
+
1259
+
1260
+
1261
+	/**
1262
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1263
+	 * @return array|bool
1264
+	 * @throws \EE_Error
1265
+	 */
1266
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1267
+		EE_Message_Resource_Manager $message_resource_manager
1268
+	) {
1269
+		/** @type EE_messenger[] $active_messengers */
1270
+		$active_messengers = $message_resource_manager->active_messengers();
1271
+		$installed_message_types = $message_resource_manager->installed_message_types();
1272
+		$templates_created = false;
1273
+		foreach ($active_messengers as $active_messenger) {
1274
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1275
+			$default_message_type_names_to_activate = array();
1276
+			// looping through each default message type reported by the messenger
1277
+			// and setup the actual message types to activate.
1278
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1279
+				// if already active or has already been activated before we skip
1280
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1281
+				// we also skip if the message type is not installed.
1282
+				if ($message_resource_manager->has_message_type_been_activated_for_messenger(
1283
+					$default_message_type_name_for_messenger,
1284
+					$active_messenger->name
1285
+				)
1286
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1287
+						$active_messenger->name,
1288
+						$default_message_type_name_for_messenger
1289
+					)
1290
+					|| ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1291
+				) {
1292
+					continue;
1293
+				}
1294
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1295
+			}
1296
+			// let's activate!
1297
+			$message_resource_manager->ensure_message_types_are_active(
1298
+				$default_message_type_names_to_activate,
1299
+				$active_messenger->name,
1300
+				false
1301
+			);
1302
+			// activate the templates for these message types
1303
+			if (! empty($default_message_type_names_to_activate)) {
1304
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1305
+					$active_messenger->name,
1306
+					$default_message_type_names_for_messenger,
1307
+					'',
1308
+					true
1309
+				);
1310
+			}
1311
+		}
1312
+		return $templates_created;
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 * This will activate and generate default messengers and default message types for those messengers.
1319
+	 *
1320
+	 * @param EE_message_Resource_Manager $message_resource_manager
1321
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1322
+	 *                     False means that there were no templates generated
1323
+	 *                     (which could simply mean there are no default message types for a messenger).
1324
+	 * @throws EE_Error
1325
+	 */
1326
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1327
+		EE_Message_Resource_Manager $message_resource_manager
1328
+	) {
1329
+		/** @type EE_messenger[] $messengers_to_generate */
1330
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1331
+		$installed_message_types = $message_resource_manager->installed_message_types();
1332
+		$templates_generated = false;
1333
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1334
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1335
+			// verify the default message types match an installed message type.
1336
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1337
+				if (! isset($installed_message_types[ $name ])
1338
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1339
+						$name,
1340
+						$messenger_to_generate->name
1341
+					)
1342
+				) {
1343
+					unset($default_message_type_names_for_messenger[ $key ]);
1344
+				}
1345
+			}
1346
+			// in previous iterations, the active_messengers option in the db
1347
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1348
+			// This comment is left here just in case we discover that we _do_ need to update before
1349
+			// passing off to create templates (after the refactor is done).
1350
+			// @todo remove this comment when determined not necessary.
1351
+			$message_resource_manager->activate_messenger(
1352
+				$messenger_to_generate->name,
1353
+				$default_message_type_names_for_messenger,
1354
+				false
1355
+			);
1356
+			// create any templates needing created (or will reactivate templates already generated as necessary).
1357
+			if (! empty($default_message_type_names_for_messenger)) {
1358
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1359
+					$messenger_to_generate->name,
1360
+					$default_message_type_names_for_messenger,
1361
+					'',
1362
+					true
1363
+				);
1364
+			}
1365
+		}
1366
+		return $templates_generated;
1367
+	}
1368
+
1369
+
1370
+	/**
1371
+	 * This returns the default messengers to generate templates for on activation of EE.
1372
+	 * It considers:
1373
+	 * - whether a messenger is already active in the db.
1374
+	 * - whether a messenger has been made active at any time in the past.
1375
+	 *
1376
+	 * @static
1377
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1378
+	 * @return EE_messenger[]
1379
+	 */
1380
+	protected static function _get_default_messengers_to_generate_on_activation(
1381
+		EE_Message_Resource_Manager $message_resource_manager
1382
+	) {
1383
+		$active_messengers    = $message_resource_manager->active_messengers();
1384
+		$installed_messengers = $message_resource_manager->installed_messengers();
1385
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1386
+
1387
+		$messengers_to_generate = array();
1388
+		foreach ($installed_messengers as $installed_messenger) {
1389
+			// if installed messenger is a messenger that should be activated on install
1390
+			// and is not already active
1391
+			// and has never been activated
1392
+			if (! $installed_messenger->activate_on_install
1393
+				|| isset($active_messengers[ $installed_messenger->name ])
1394
+				|| isset($has_activated[ $installed_messenger->name ])
1395
+			) {
1396
+				continue;
1397
+			}
1398
+			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1399
+		}
1400
+		return $messengers_to_generate;
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * This simply validates active message types to ensure they actually match installed
1406
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1407
+	 * rows are set inactive.
1408
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1409
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1410
+	 * are still handled in here.
1411
+	 *
1412
+	 * @since 4.3.1
1413
+	 * @return void
1414
+	 */
1415
+	public static function validate_messages_system()
1416
+	{
1417
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1418
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1419
+		$message_resource_manager->validate_active_message_types_are_installed();
1420
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1421
+	}
1422
+
1423
+
1424
+	/**
1425
+	 * create_no_ticket_prices_array
1426
+	 *
1427
+	 * @access public
1428
+	 * @static
1429
+	 * @return void
1430
+	 */
1431
+	public static function create_no_ticket_prices_array()
1432
+	{
1433
+		// this creates an array for tracking events that have no active ticket prices created
1434
+		// this allows us to warn admins of the situation so that it can be corrected
1435
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1436
+		if (! $espresso_no_ticket_prices) {
1437
+			add_option('ee_no_ticket_prices', array(), '', false);
1438
+		}
1439
+	}
1440
+
1441
+
1442
+	/**
1443
+	 * plugin_deactivation
1444
+	 *
1445
+	 * @access public
1446
+	 * @static
1447
+	 * @return void
1448
+	 */
1449
+	public static function plugin_deactivation()
1450
+	{
1451
+	}
1452
+
1453
+
1454
+	/**
1455
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1456
+	 * (like post meta or term relations)
1457
+	 *
1458
+	 * @global wpdb $wpdb
1459
+	 * @throws \EE_Error
1460
+	 */
1461
+	public static function delete_all_espresso_cpt_data()
1462
+	{
1463
+		global $wpdb;
1464
+		// get all the CPT post_types
1465
+		$ee_post_types = array();
1466
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1467
+			if (method_exists($model_name, 'instance')) {
1468
+				$model_obj = call_user_func(array($model_name, 'instance'));
1469
+				if ($model_obj instanceof EEM_CPT_Base) {
1470
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1471
+				}
1472
+			}
1473
+		}
1474
+		// get all our CPTs
1475
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1476
+		$cpt_ids = $wpdb->get_col($query);
1477
+		// delete each post meta and term relations too
1478
+		foreach ($cpt_ids as $post_id) {
1479
+			wp_delete_post($post_id, true);
1480
+		}
1481
+	}
1482
+
1483
+	/**
1484
+	 * Deletes all EE custom tables
1485
+	 *
1486
+	 * @return array
1487
+	 */
1488
+	public static function drop_espresso_tables()
1489
+	{
1490
+		$tables = array();
1491
+		// load registry
1492
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1493
+			if (method_exists($model_name, 'instance')) {
1494
+				$model_obj = call_user_func(array($model_name, 'instance'));
1495
+				if ($model_obj instanceof EEM_Base) {
1496
+					foreach ($model_obj->get_tables() as $table) {
1497
+						if (strpos($table->get_table_name(), 'esp_')
1498
+							&&
1499
+							(
1500
+								is_main_site()// main site? nuke them all
1501
+								|| ! $table->is_global()// not main site,but not global either. nuke it
1502
+							)
1503
+						) {
1504
+							$tables[ $table->get_table_name() ] = $table->get_table_name();
1505
+						}
1506
+					}
1507
+				}
1508
+			}
1509
+		}
1510
+
1511
+		// there are some tables whose models were removed.
1512
+		// they should be removed when removing all EE core's data
1513
+		$tables_without_models = array(
1514
+			'esp_promotion',
1515
+			'esp_promotion_applied',
1516
+			'esp_promotion_object',
1517
+			'esp_promotion_rule',
1518
+			'esp_rule',
1519
+		);
1520
+		foreach ($tables_without_models as $table) {
1521
+			$tables[ $table ] = $table;
1522
+		}
1523
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1524
+	}
1525
+
1526
+
1527
+
1528
+	/**
1529
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1530
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1531
+	 * Returns the list actually deleted
1532
+	 *
1533
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1534
+	 * @global WPDB $wpdb
1535
+	 * @param array $table_names
1536
+	 * @return array of table names which we deleted
1537
+	 */
1538
+	public static function drop_tables($table_names)
1539
+	{
1540
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1541
+	}
1542
+
1543
+
1544
+
1545
+	/**
1546
+	 * plugin_uninstall
1547
+	 *
1548
+	 * @access public
1549
+	 * @static
1550
+	 * @param bool $remove_all
1551
+	 * @return void
1552
+	 */
1553
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1554
+	{
1555
+		global $wpdb;
1556
+		self::drop_espresso_tables();
1557
+		$wp_options_to_delete = array(
1558
+			'ee_no_ticket_prices'                => true,
1559
+			'ee_active_messengers'               => true,
1560
+			'ee_has_activated_messenger'         => true,
1561
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1562
+			'ee_config'                          => false,
1563
+			'ee_data_migration_current_db_state' => true,
1564
+			'ee_data_migration_mapping_'         => false,
1565
+			'ee_data_migration_script_'          => false,
1566
+			'ee_data_migrations'                 => true,
1567
+			'ee_dms_map'                         => false,
1568
+			'ee_notices'                         => true,
1569
+			'lang_file_check_'                   => false,
1570
+			'ee_maintenance_mode'                => true,
1571
+			'ee_ueip_optin'                      => true,
1572
+			'ee_ueip_has_notified'               => true,
1573
+			'ee_plugin_activation_errors'        => true,
1574
+			'ee_id_mapping_from'                 => false,
1575
+			'espresso_persistent_admin_notices'  => true,
1576
+			'ee_encryption_key'                  => true,
1577
+			'pue_force_upgrade_'                 => false,
1578
+			'pue_json_error_'                    => false,
1579
+			'pue_install_key_'                   => false,
1580
+			'pue_verification_error_'            => false,
1581
+			'pu_dismissed_upgrade_'              => false,
1582
+			'external_updates-'                  => false,
1583
+			'ee_extra_data'                      => true,
1584
+			'ee_ssn_'                            => false,
1585
+			'ee_rss_'                            => false,
1586
+			'ee_rte_n_tx_'                       => false,
1587
+			'ee_pers_admin_notices'              => true,
1588
+			'ee_job_parameters_'                 => false,
1589
+			'ee_upload_directories_incomplete'   => true,
1590
+			'ee_verified_db_collations'          => true,
1591
+		);
1592
+		if (is_main_site()) {
1593
+			$wp_options_to_delete['ee_network_config'] = true;
1594
+		}
1595
+		$undeleted_options = array();
1596
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1597
+			if ($no_wildcard) {
1598
+				if (! delete_option($option_name)) {
1599
+					$undeleted_options[] = $option_name;
1600
+				}
1601
+			} else {
1602
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1603
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1604
+					if (! delete_option($option_name_from_wildcard)) {
1605
+						$undeleted_options[] = $option_name_from_wildcard;
1606
+					}
1607
+				}
1608
+			}
1609
+		}
1610
+		// also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1611
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1612
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1613
+			$db_update_sans_ee4 = array();
1614
+			foreach ($espresso_db_update as $version => $times_activated) {
1615
+				if ((string) $version[0] === '3') {// if its NON EE4
1616
+					$db_update_sans_ee4[ $version ] = $times_activated;
1617
+				}
1618
+			}
1619
+			update_option('espresso_db_update', $db_update_sans_ee4);
1620
+		}
1621
+		$errors = '';
1622
+		if (! empty($undeleted_options)) {
1623
+			$errors .= sprintf(
1624
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1625
+				'<br/>',
1626
+				implode(',<br/>', $undeleted_options)
1627
+			);
1628
+		}
1629
+		if (! empty($errors)) {
1630
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1631
+		}
1632
+	}
1633
+
1634
+	/**
1635
+	 * Gets the mysql error code from the last used query by wpdb
1636
+	 *
1637
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1638
+	 */
1639
+	public static function last_wpdb_error_code()
1640
+	{
1641
+		// phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved
1642
+		global $wpdb;
1643
+		if ($wpdb->use_mysqli) {
1644
+			return mysqli_errno($wpdb->dbh);
1645
+		} else {
1646
+			return mysql_errno($wpdb->dbh);
1647
+		}
1648
+		// phpcs:enable
1649
+	}
1650
+
1651
+	/**
1652
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1653
+	 *
1654
+	 * @global wpdb  $wpdb
1655
+	 * @deprecated instead use TableAnalysis::tableExists()
1656
+	 * @param string $table_name with or without $wpdb->prefix
1657
+	 * @return boolean
1658
+	 */
1659
+	public static function table_exists($table_name)
1660
+	{
1661
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1662
+	}
1663
+
1664
+	/**
1665
+	 * Resets the cache on EEH_Activation
1666
+	 */
1667
+	public static function reset()
1668
+	{
1669
+		self::$_default_creator_id                             = null;
1670
+		self::$_initialized_db_content_already_in_this_request = false;
1671
+	}
1672
+
1673
+	/**
1674
+	 * Removes 'email_confirm' from the Address info question group on activation
1675
+	 * @return void
1676
+	 */
1677
+	public static function removeEmailConfirmFromAddressGroup()
1678
+	{
1679
+
1680
+		// Pull the email_confirm question ID.
1681
+		$email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(
1682
+			EEM_Attendee::system_question_email_confirm
1683
+		);
1684
+		// Remove the email_confirm question group from the address group questions.
1685
+		EEM_Question_Group_Question::instance()->delete(
1686
+			array(
1687
+				array(
1688
+					'QST_ID' => $email_confirm_question_id,
1689
+					'Question_Group.QSG_system' => EEM_Question_Group::system_address,
1690
+				),
1691
+			)
1692
+		);
1693
+	}
1694 1694
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public static function getTableAnalysis()
56 56
     {
57
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
57
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58 58
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59 59
         }
60 60
         return self::$table_analysis;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function getTableManager()
68 68
     {
69
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
69
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70 70
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71 71
         }
72 72
         return self::$table_manager;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         if ($which_to_include === 'old') {
182 182
             $cron_tasks = array_filter(
183 183
                 $cron_tasks,
184
-                function ($value) {
184
+                function($value) {
185 185
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
186 186
                 }
187 187
             );
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     {
212 212
 
213 213
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
214
-            if (! wp_next_scheduled($hook_name)) {
214
+            if ( ! wp_next_scheduled($hook_name)) {
215 215
                 /**
216 216
                  * This allows client code to define the initial start timestamp for this schedule.
217 217
                  */
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
         foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
263 263
             if (is_array($hooks_to_fire_at_time)) {
264 264
                 foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
265
-                    if (isset($ee_cron_tasks_to_remove[ $hook_name ])
266
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
265
+                    if (isset($ee_cron_tasks_to_remove[$hook_name])
266
+                        && is_array($ee_cron_tasks_to_remove[$hook_name])
267 267
                     ) {
268
-                        unset($crons[ $timestamp ][ $hook_name ]);
268
+                        unset($crons[$timestamp][$hook_name]);
269 269
                     }
270 270
                 }
271 271
                 // also take care of any empty cron timestamps.
272 272
                 if (empty($hooks_to_fire_at_time)) {
273
-                    unset($crons[ $timestamp ]);
273
+                    unset($crons[$timestamp]);
274 274
                 }
275 275
             }
276 276
         }
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             3
316 316
         );
317 317
         // EE_Config::reset();
318
-        if (! EE_Config::logging_enabled()) {
318
+        if ( ! EE_Config::logging_enabled()) {
319 319
             delete_option(EE_Config::LOG_NAME);
320 320
         }
321 321
     }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
     public static function load_calendar_config()
331 331
     {
332 332
         // grab array of all plugin folders and loop thru it
333
-        $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR);
333
+        $plugins = glob(WP_PLUGIN_DIR.'/*', GLOB_ONLYDIR);
334 334
         if (empty($plugins)) {
335 335
             return;
336 336
         }
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
                 || strpos($plugin, 'calendar') !== false
347 347
             ) {
348 348
                 // this is what we are looking for
349
-                $calendar_config = $plugin_path . '/EE_Calendar_Config.php';
349
+                $calendar_config = $plugin_path.'/EE_Calendar_Config.php';
350 350
                 // does it exist in this folder ?
351 351
                 if (is_readable($calendar_config)) {
352 352
                     // YEAH! let's load it
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
             ) {
474 474
                 // update Config with post ID
475 475
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
476
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
476
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
477 477
                     $msg = __(
478 478
                         'The Event Espresso critical page configuration settings could not be updated.',
479 479
                         'event_espresso'
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
497 497
                         'event_espresso'
498 498
                     ),
499
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
499
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
500 500
                     . __('Event Espresso Critical Pages Settings', 'event_espresso')
501 501
                     . '</a>'
502 502
                 )
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
     public static function get_page_by_ee_shortcode($ee_shortcode)
523 523
     {
524 524
         global $wpdb;
525
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
525
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
526 526
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
527 527
         if ($post_id) {
528 528
             return get_post($post_id);
@@ -548,11 +548,11 @@  discard block
 block discarded – undo
548 548
             'post_status'    => 'publish',
549 549
             'post_type'      => 'page',
550 550
             'comment_status' => 'closed',
551
-            'post_content'   => '[' . $critical_page['code'] . ']',
551
+            'post_content'   => '['.$critical_page['code'].']',
552 552
         );
553 553
 
554 554
         $post_id = wp_insert_post($post_args);
555
-        if (! $post_id) {
555
+        if ( ! $post_id) {
556 556
             $msg = sprintf(
557 557
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
558 558
                 $critical_page['name']
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
             return $critical_page;
562 562
         }
563 563
         // get newly created post's details
564
-        if (! $critical_page['post'] = get_post($post_id)) {
564
+        if ( ! $critical_page['post'] = get_post($post_id)) {
565 565
             $msg = sprintf(
566 566
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
567 567
                 $critical_page['name']
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
     public static function get_default_creator_id()
587 587
     {
588 588
         global $wpdb;
589
-        if (! empty(self::$_default_creator_id)) {
589
+        if ( ! empty(self::$_default_creator_id)) {
590 590
             return self::$_default_creator_id;
591 591
         }/**/
592 592
         $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
603 603
         $query = $wpdb->prepare(
604 604
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
605
-            '%' . $role_to_check . '%'
605
+            '%'.$role_to_check.'%'
606 606
         );
607 607
         $user_id = $wpdb->get_var($query);
608 608
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
@@ -641,8 +641,8 @@  discard block
 block discarded – undo
641 641
             return;
642 642
         }
643 643
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
644
-        if (! function_exists('dbDelta')) {
645
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
644
+        if ( ! function_exists('dbDelta')) {
645
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
646 646
         }
647 647
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
648 648
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
             // ok, delete the table... but ONLY if it's empty
652 652
             $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
653 653
             // table is NOT empty, are you SURE you want to delete this table ???
654
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654
+            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
655 655
                 \EEH_Activation::getTableManager()->dropTable($wp_table_name);
656
-            } elseif (! $deleted_safely) {
656
+            } elseif ( ! $deleted_safely) {
657 657
                 // so we should be more cautious rather than just dropping tables so easily
658 658
                 error_log(
659 659
                     sprintf(
@@ -853,13 +853,13 @@  discard block
 block discarded – undo
853 853
             // reset values array
854 854
             $QSG_values = array();
855 855
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
856
-            if (! in_array("$QSG_system", $question_groups)) {
856
+            if ( ! in_array("$QSG_system", $question_groups)) {
857 857
                 // add it
858 858
                 switch ($QSG_system) {
859 859
                     case 1:
860 860
                         $QSG_values = array(
861 861
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
862
-                            'QSG_identifier'      => 'personal-information-' . time(),
862
+                            'QSG_identifier'      => 'personal-information-'.time(),
863 863
                             'QSG_desc'            => '',
864 864
                             'QSG_order'           => 1,
865 865
                             'QSG_show_group_name' => 1,
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
                     case 2:
872 872
                         $QSG_values = array(
873 873
                             'QSG_name'            => __('Address Information', 'event_espresso'),
874
-                            'QSG_identifier'      => 'address-information-' . time(),
874
+                            'QSG_identifier'      => 'address-information-'.time(),
875 875
                             'QSG_desc'            => '',
876 876
                             'QSG_order'           => 2,
877 877
                             'QSG_show_group_name' => 1,
@@ -882,14 +882,14 @@  discard block
 block discarded – undo
882 882
                         break;
883 883
                 }
884 884
                 // make sure we have some values before inserting them
885
-                if (! empty($QSG_values)) {
885
+                if ( ! empty($QSG_values)) {
886 886
                     // insert system question
887 887
                     $wpdb->insert(
888 888
                         $table_name,
889 889
                         $QSG_values,
890 890
                         array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
891 891
                     );
892
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
892
+                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
893 893
                 }
894 894
             }
895 895
         }
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
             // reset values array
917 917
             $QST_values = array();
918 918
             // if we don't have what we should have
919
-            if (! in_array($QST_system, $questions)) {
919
+            if ( ! in_array($QST_system, $questions)) {
920 920
                 // add it
921 921
                 switch ($QST_system) {
922 922
                     case 'fname':
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
                         );
1084 1084
                         break;
1085 1085
                 }
1086
-                if (! empty($QST_values)) {
1086
+                if ( ! empty($QST_values)) {
1087 1087
                     // insert system question
1088 1088
                     $wpdb->insert(
1089 1089
                         $table_name,
@@ -1101,8 +1101,8 @@  discard block
 block discarded – undo
1101 1101
                         // QST_system should not be assigned to any group
1102 1102
                         continue;
1103 1103
                     }
1104
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1105
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1104
+                    if (isset($QSG_IDs[$system_question_we_want])) {
1105
+                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1106 1106
                     } else {
1107 1107
                         $id_col = EEM_Question_Group::instance()
1108 1108
                                                     ->get_col(array(array('QSG_system' => $system_question_we_want)));
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
      */
1151 1151
     public static function insert_default_payment_methods()
1152 1152
     {
1153
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1153
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1154 1154
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1155 1155
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1156 1156
         } else {
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
                         $active_messenger->name,
1288 1288
                         $default_message_type_name_for_messenger
1289 1289
                     )
1290
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1290
+                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1291 1291
                 ) {
1292 1292
                     continue;
1293 1293
                 }
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
                 false
1301 1301
             );
1302 1302
             // activate the templates for these message types
1303
-            if (! empty($default_message_type_names_to_activate)) {
1303
+            if ( ! empty($default_message_type_names_to_activate)) {
1304 1304
                 $templates_created = EEH_MSG_Template::generate_new_templates(
1305 1305
                     $active_messenger->name,
1306 1306
                     $default_message_type_names_for_messenger,
@@ -1334,13 +1334,13 @@  discard block
 block discarded – undo
1334 1334
             $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1335 1335
             // verify the default message types match an installed message type.
1336 1336
             foreach ($default_message_type_names_for_messenger as $key => $name) {
1337
-                if (! isset($installed_message_types[ $name ])
1337
+                if ( ! isset($installed_message_types[$name])
1338 1338
                     || $message_resource_manager->has_message_type_been_activated_for_messenger(
1339 1339
                         $name,
1340 1340
                         $messenger_to_generate->name
1341 1341
                     )
1342 1342
                 ) {
1343
-                    unset($default_message_type_names_for_messenger[ $key ]);
1343
+                    unset($default_message_type_names_for_messenger[$key]);
1344 1344
                 }
1345 1345
             }
1346 1346
             // in previous iterations, the active_messengers option in the db
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
                 false
1355 1355
             );
1356 1356
             // create any templates needing created (or will reactivate templates already generated as necessary).
1357
-            if (! empty($default_message_type_names_for_messenger)) {
1357
+            if ( ! empty($default_message_type_names_for_messenger)) {
1358 1358
                 $templates_generated = EEH_MSG_Template::generate_new_templates(
1359 1359
                     $messenger_to_generate->name,
1360 1360
                     $default_message_type_names_for_messenger,
@@ -1389,13 +1389,13 @@  discard block
 block discarded – undo
1389 1389
             // if installed messenger is a messenger that should be activated on install
1390 1390
             // and is not already active
1391 1391
             // and has never been activated
1392
-            if (! $installed_messenger->activate_on_install
1393
-                || isset($active_messengers[ $installed_messenger->name ])
1394
-                || isset($has_activated[ $installed_messenger->name ])
1392
+            if ( ! $installed_messenger->activate_on_install
1393
+                || isset($active_messengers[$installed_messenger->name])
1394
+                || isset($has_activated[$installed_messenger->name])
1395 1395
             ) {
1396 1396
                 continue;
1397 1397
             }
1398
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1398
+            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1399 1399
         }
1400 1400
         return $messengers_to_generate;
1401 1401
     }
@@ -1433,7 +1433,7 @@  discard block
 block discarded – undo
1433 1433
         // this creates an array for tracking events that have no active ticket prices created
1434 1434
         // this allows us to warn admins of the situation so that it can be corrected
1435 1435
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1436
-        if (! $espresso_no_ticket_prices) {
1436
+        if ( ! $espresso_no_ticket_prices) {
1437 1437
             add_option('ee_no_ticket_prices', array(), '', false);
1438 1438
         }
1439 1439
     }
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
             }
1473 1473
         }
1474 1474
         // get all our CPTs
1475
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1475
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1476 1476
         $cpt_ids = $wpdb->get_col($query);
1477 1477
         // delete each post meta and term relations too
1478 1478
         foreach ($cpt_ids as $post_id) {
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
                                 || ! $table->is_global()// not main site,but not global either. nuke it
1502 1502
                             )
1503 1503
                         ) {
1504
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1504
+                            $tables[$table->get_table_name()] = $table->get_table_name();
1505 1505
                         }
1506 1506
                     }
1507 1507
                 }
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
             'esp_rule',
1519 1519
         );
1520 1520
         foreach ($tables_without_models as $table) {
1521
-            $tables[ $table ] = $table;
1521
+            $tables[$table] = $table;
1522 1522
         }
1523 1523
         return \EEH_Activation::getTableManager()->dropTables($tables);
1524 1524
     }
@@ -1595,13 +1595,13 @@  discard block
 block discarded – undo
1595 1595
         $undeleted_options = array();
1596 1596
         foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1597 1597
             if ($no_wildcard) {
1598
-                if (! delete_option($option_name)) {
1598
+                if ( ! delete_option($option_name)) {
1599 1599
                     $undeleted_options[] = $option_name;
1600 1600
                 }
1601 1601
             } else {
1602 1602
                 $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1603 1603
                 foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1604
-                    if (! delete_option($option_name_from_wildcard)) {
1604
+                    if ( ! delete_option($option_name_from_wildcard)) {
1605 1605
                         $undeleted_options[] = $option_name_from_wildcard;
1606 1606
                     }
1607 1607
                 }
@@ -1613,20 +1613,20 @@  discard block
 block discarded – undo
1613 1613
             $db_update_sans_ee4 = array();
1614 1614
             foreach ($espresso_db_update as $version => $times_activated) {
1615 1615
                 if ((string) $version[0] === '3') {// if its NON EE4
1616
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1616
+                    $db_update_sans_ee4[$version] = $times_activated;
1617 1617
                 }
1618 1618
             }
1619 1619
             update_option('espresso_db_update', $db_update_sans_ee4);
1620 1620
         }
1621 1621
         $errors = '';
1622
-        if (! empty($undeleted_options)) {
1622
+        if ( ! empty($undeleted_options)) {
1623 1623
             $errors .= sprintf(
1624 1624
                 __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1625 1625
                 '<br/>',
1626 1626
                 implode(',<br/>', $undeleted_options)
1627 1627
             );
1628 1628
         }
1629
-        if (! empty($errors)) {
1629
+        if ( ! empty($errors)) {
1630 1630
             EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1631 1631
         }
1632 1632
     }
Please login to merge, or discard this patch.
core/helpers/EEH_Schema.helper.php 2 patches
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -12,296 +12,296 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * generates JSON-based linked data for an event
17
-     *
18
-     * @param EE_Event $event
19
-     * @throws EE_Error
20
-     */
21
-    public static function add_json_linked_data_for_event(EE_Event $event)
22
-    {
23
-        // Check we have a valid datetime for the event
24
-        if (! $event->primary_datetime() instanceof EE_Datetime) {
25
-            return;
26
-        }
27
-
28
-        $template_args = array(
29
-            'event_permalink' => '',
30
-            'event_name' => '',
31
-            'event_description' => '',
32
-            'event_start' => '',
33
-            'event_end' => '',
34
-            'event_attendance_mode' => '',
35
-            'event_status' => '',
36
-            'currency' => '',
37
-            'event_tickets' => array(),
38
-            'venue_name' => '',
39
-            'venue_url' => '',
40
-            'venue_locality' => '',
41
-            'venue_region' => '',
42
-            'venue_address' => '',
43
-            'event_image' => '',
44
-        );
45
-        $template_args['event_permalink'] = $event->get_permalink();
46
-        $template_args['event_name'] = $event->name();
47
-        $template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
48
-        // clone datetime so that date formats don't override those for the original datetime
49
-        $primary_datetime = clone $event->primary_datetime();
50
-        $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM);
51
-        $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM);
52
-        unset($primary_datetime);
53
-        switch ($event->status()) {
54
-            case EEM_Event::cancelled:
55
-                $event_status = 'EventCancelled';
56
-                break;
57
-            case EEM_Event::postponed:
58
-                $event_status = 'EventPostponed';
59
-                break;
60
-            default:
61
-                $event_status = 'EventScheduled';
62
-        }
63
-        $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode';
64
-        $template_args['event_status'] = '"https://schema.org/' . $event_status . '"';
65
-        $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
66
-        foreach ($event->tickets() as $original_ticket) {
67
-            // clone tickets so that date formats don't override those for the original ticket
68
-            $ticket= clone $original_ticket;
69
-            $ID = $ticket->ID();
70
-            $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
-            $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
-            $template_args['event_tickets'][ $ID ]['price'] = number_format(
73
-                $ticket->price(),
74
-                EE_Registry::instance()->CFG->currency->dec_plc,
75
-                EE_Registry::instance()->CFG->currency->dec_mrk,
76
-                ''
77
-            );
78
-            switch ($ticket->ticket_status()) {
79
-                case 'TKO':
80
-                    $availability = 'InStock';
81
-                    break;
82
-                case 'TKS':
83
-                    $availability = 'SoldOut';
84
-                    break;
85
-                default:
86
-                    $availability = null;
87
-                    break;
88
-            }
89
-            $template_args['event_tickets'][ $ID ]['availability'] = $availability;
90
-            unset($ticket);
91
-        }
92
-        $VNU_ID = espresso_venue_id();
93
-        if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
94
-            $venue = EEH_Venue_View::get_venue($VNU_ID);
95
-            $template_args['venue_name'] = get_the_title($VNU_ID);
96
-            $template_args['venue_url'] = get_permalink($VNU_ID);
97
-            $template_args['venue_locality'] = $venue->city();
98
-            $template_args['venue_region'] = $venue->state_name();
99
-            $template_args['venue_address'] = $venue->address();
100
-            if ($venue->virtual_url() !== '') {
101
-                $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode';
102
-            }
103
-            if ($venue->virtual_url() !== '' && $venue->address() !== '') {
104
-                $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode';
105
-            }
106
-        }
107
-        $template_args['event_image'] = $event->feature_image_url();
108
-        $template_args = apply_filters(
109
-            'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
110
-            $template_args,
111
-            $event,
112
-            $VNU_ID
113
-        );
114
-        extract($template_args, EXTR_OVERWRITE);
115
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
116
-    }
117
-
118
-
119
-    /**
120
-     *    location
121
-     *    The location of the event, organization or action.
122
-     *    Should include the Venue name AND schema formatted address info
123
-     *
124
-     * @access public
125
-     * @param string $location
126
-     * @return string
127
-     */
128
-    public static function location($location = null)
129
-    {
130
-        return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
131
-                                      . $location
132
-                                      . '</div>' : '';
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     *    name
139
-     *    The name of the Event or Venue.
140
-     *
141
-     * @access public
142
-     * @param string $name
143
-     * @return string
144
-     */
145
-    public static function name($name = null)
146
-    {
147
-        return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : '';
148
-    }
149
-
150
-
151
-
152
-    /**
153
-     *    streetAddress
154
-     *    The street address. For example, 1600 Amphitheatre Pkwy.
155
-     *
156
-     * @access public
157
-     * @param EEI_Address $obj_with_address
158
-     * @return string
159
-     */
160
-    public static function streetAddress(EEI_Address $obj_with_address = null)
161
-    {
162
-        return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
163
-            ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     *    postOfficeBoxNumber
170
-     *    The post office box number for PO box addresses.
171
-     *
172
-     * @access public
173
-     * @param EEI_Address $obj_with_address
174
-     * @return string
175
-     */
176
-    public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null)
177
-    {
178
-        // regex check for some form of PO Box or P.O. Box, etc, etc, etc
179
-        if (preg_match(
180
-            "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
181
-            $obj_with_address->address2()
182
-        ) ) {
183
-            return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
184
-                ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
185
-        } else {
186
-            return $obj_with_address->address2();
187
-        }
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     *    addressLocality
194
-     *    The locality (city, town, etc). For example, Mountain View.
195
-     *
196
-     * @access public
197
-     * @param EEI_Address $obj_with_address
198
-     * @return string
199
-     */
200
-    public static function addressLocality(EEI_Address $obj_with_address = null)
201
-    {
202
-        return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
203
-            ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     *    addressRegion
210
-     *    The region (state, province, etc). For example, CA.
211
-     *
212
-     * @access public
213
-     * @param EEI_Address $obj_with_address
214
-     * @return string
215
-     */
216
-    public static function addressRegion(EEI_Address $obj_with_address = null)
217
-    {
218
-        $state = $obj_with_address->state_name();
219
-        if (! empty($state)) {
220
-            return '<span itemprop="addressRegion">' . $state . '</span>';
221
-        } else {
222
-            return '';
223
-        }
224
-    }
225
-
226
-
227
-
228
-    /**
229
-     *    addressCountry
230
-     *    The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code.
231
-     *
232
-     * @access public
233
-     * @param EEI_Address $obj_with_address
234
-     * @return string
235
-     */
236
-    public static function addressCountry(EEI_Address $obj_with_address = null)
237
-    {
238
-        $country = $obj_with_address->country_name();
239
-        if (! empty($country)) {
240
-            return '<span itemprop="addressCountry">' . $country . '</span>';
241
-        } else {
242
-            return '';
243
-        }
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     *    postalCode
250
-     *    The postal code. For example, 94043.
251
-     *
252
-     * @access public
253
-     * @param EEI_Address $obj_with_address
254
-     * @return string
255
-     */
256
-    public static function postalCode(EEI_Address $obj_with_address = null)
257
-    {
258
-        return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
259
-                                                                                      . $obj_with_address->zip()
260
-                                                                                      . '</span>' : '';
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     *    telephone
267
-     *    The telephone number.
268
-     *
269
-     * @access public
270
-     * @param string $phone_nmbr
271
-     * @return string
272
-     */
273
-    public static function telephone($phone_nmbr = null)
274
-    {
275
-        return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
276
-            : '';
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     *    URL
283
-     *    URL of the item as a clickable link
284
-     *
285
-     * @access public
286
-     * @param string $url        - the URL that the link will resolve to
287
-     * @param string $text       - the text that will be used for the visible link
288
-     * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
289
-     * @return string (link)
290
-     */
291
-    public static function url($url = null, $text = null, $attributes = array())
292
-    {
293
-        // Check the URL includes a scheme
294
-        $parsed_url = parse_url($url);
295
-        if (empty($parsed_url['scheme'])) {
296
-            $url = 'http://' . ltrim($url, '/');
297
-        }
298
-
299
-        $atts = '';
300
-        foreach ($attributes as $attribute => $value) {
301
-            $atts .= ' ' . $attribute . '="' . $value . '"';
302
-        }
303
-        $text = $text !== null && $text !== '' ? $text : $url;
304
-        return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>'
305
-            : '';
306
-    }
15
+	/**
16
+	 * generates JSON-based linked data for an event
17
+	 *
18
+	 * @param EE_Event $event
19
+	 * @throws EE_Error
20
+	 */
21
+	public static function add_json_linked_data_for_event(EE_Event $event)
22
+	{
23
+		// Check we have a valid datetime for the event
24
+		if (! $event->primary_datetime() instanceof EE_Datetime) {
25
+			return;
26
+		}
27
+
28
+		$template_args = array(
29
+			'event_permalink' => '',
30
+			'event_name' => '',
31
+			'event_description' => '',
32
+			'event_start' => '',
33
+			'event_end' => '',
34
+			'event_attendance_mode' => '',
35
+			'event_status' => '',
36
+			'currency' => '',
37
+			'event_tickets' => array(),
38
+			'venue_name' => '',
39
+			'venue_url' => '',
40
+			'venue_locality' => '',
41
+			'venue_region' => '',
42
+			'venue_address' => '',
43
+			'event_image' => '',
44
+		);
45
+		$template_args['event_permalink'] = $event->get_permalink();
46
+		$template_args['event_name'] = $event->name();
47
+		$template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
48
+		// clone datetime so that date formats don't override those for the original datetime
49
+		$primary_datetime = clone $event->primary_datetime();
50
+		$template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM);
51
+		$template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM);
52
+		unset($primary_datetime);
53
+		switch ($event->status()) {
54
+			case EEM_Event::cancelled:
55
+				$event_status = 'EventCancelled';
56
+				break;
57
+			case EEM_Event::postponed:
58
+				$event_status = 'EventPostponed';
59
+				break;
60
+			default:
61
+				$event_status = 'EventScheduled';
62
+		}
63
+		$template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode';
64
+		$template_args['event_status'] = '"https://schema.org/' . $event_status . '"';
65
+		$template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
66
+		foreach ($event->tickets() as $original_ticket) {
67
+			// clone tickets so that date formats don't override those for the original ticket
68
+			$ticket= clone $original_ticket;
69
+			$ID = $ticket->ID();
70
+			$template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
+			$template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
+			$template_args['event_tickets'][ $ID ]['price'] = number_format(
73
+				$ticket->price(),
74
+				EE_Registry::instance()->CFG->currency->dec_plc,
75
+				EE_Registry::instance()->CFG->currency->dec_mrk,
76
+				''
77
+			);
78
+			switch ($ticket->ticket_status()) {
79
+				case 'TKO':
80
+					$availability = 'InStock';
81
+					break;
82
+				case 'TKS':
83
+					$availability = 'SoldOut';
84
+					break;
85
+				default:
86
+					$availability = null;
87
+					break;
88
+			}
89
+			$template_args['event_tickets'][ $ID ]['availability'] = $availability;
90
+			unset($ticket);
91
+		}
92
+		$VNU_ID = espresso_venue_id();
93
+		if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
94
+			$venue = EEH_Venue_View::get_venue($VNU_ID);
95
+			$template_args['venue_name'] = get_the_title($VNU_ID);
96
+			$template_args['venue_url'] = get_permalink($VNU_ID);
97
+			$template_args['venue_locality'] = $venue->city();
98
+			$template_args['venue_region'] = $venue->state_name();
99
+			$template_args['venue_address'] = $venue->address();
100
+			if ($venue->virtual_url() !== '') {
101
+				$template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode';
102
+			}
103
+			if ($venue->virtual_url() !== '' && $venue->address() !== '') {
104
+				$template_args['event_attendance_mode'] = 'MixedEventAttendanceMode';
105
+			}
106
+		}
107
+		$template_args['event_image'] = $event->feature_image_url();
108
+		$template_args = apply_filters(
109
+			'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
110
+			$template_args,
111
+			$event,
112
+			$VNU_ID
113
+		);
114
+		extract($template_args, EXTR_OVERWRITE);
115
+		include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
116
+	}
117
+
118
+
119
+	/**
120
+	 *    location
121
+	 *    The location of the event, organization or action.
122
+	 *    Should include the Venue name AND schema formatted address info
123
+	 *
124
+	 * @access public
125
+	 * @param string $location
126
+	 * @return string
127
+	 */
128
+	public static function location($location = null)
129
+	{
130
+		return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
131
+									  . $location
132
+									  . '</div>' : '';
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 *    name
139
+	 *    The name of the Event or Venue.
140
+	 *
141
+	 * @access public
142
+	 * @param string $name
143
+	 * @return string
144
+	 */
145
+	public static function name($name = null)
146
+	{
147
+		return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : '';
148
+	}
149
+
150
+
151
+
152
+	/**
153
+	 *    streetAddress
154
+	 *    The street address. For example, 1600 Amphitheatre Pkwy.
155
+	 *
156
+	 * @access public
157
+	 * @param EEI_Address $obj_with_address
158
+	 * @return string
159
+	 */
160
+	public static function streetAddress(EEI_Address $obj_with_address = null)
161
+	{
162
+		return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
163
+			? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 *    postOfficeBoxNumber
170
+	 *    The post office box number for PO box addresses.
171
+	 *
172
+	 * @access public
173
+	 * @param EEI_Address $obj_with_address
174
+	 * @return string
175
+	 */
176
+	public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null)
177
+	{
178
+		// regex check for some form of PO Box or P.O. Box, etc, etc, etc
179
+		if (preg_match(
180
+			"/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
181
+			$obj_with_address->address2()
182
+		) ) {
183
+			return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
184
+				? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
185
+		} else {
186
+			return $obj_with_address->address2();
187
+		}
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 *    addressLocality
194
+	 *    The locality (city, town, etc). For example, Mountain View.
195
+	 *
196
+	 * @access public
197
+	 * @param EEI_Address $obj_with_address
198
+	 * @return string
199
+	 */
200
+	public static function addressLocality(EEI_Address $obj_with_address = null)
201
+	{
202
+		return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
203
+			? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 *    addressRegion
210
+	 *    The region (state, province, etc). For example, CA.
211
+	 *
212
+	 * @access public
213
+	 * @param EEI_Address $obj_with_address
214
+	 * @return string
215
+	 */
216
+	public static function addressRegion(EEI_Address $obj_with_address = null)
217
+	{
218
+		$state = $obj_with_address->state_name();
219
+		if (! empty($state)) {
220
+			return '<span itemprop="addressRegion">' . $state . '</span>';
221
+		} else {
222
+			return '';
223
+		}
224
+	}
225
+
226
+
227
+
228
+	/**
229
+	 *    addressCountry
230
+	 *    The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code.
231
+	 *
232
+	 * @access public
233
+	 * @param EEI_Address $obj_with_address
234
+	 * @return string
235
+	 */
236
+	public static function addressCountry(EEI_Address $obj_with_address = null)
237
+	{
238
+		$country = $obj_with_address->country_name();
239
+		if (! empty($country)) {
240
+			return '<span itemprop="addressCountry">' . $country . '</span>';
241
+		} else {
242
+			return '';
243
+		}
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 *    postalCode
250
+	 *    The postal code. For example, 94043.
251
+	 *
252
+	 * @access public
253
+	 * @param EEI_Address $obj_with_address
254
+	 * @return string
255
+	 */
256
+	public static function postalCode(EEI_Address $obj_with_address = null)
257
+	{
258
+		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
259
+																					  . $obj_with_address->zip()
260
+																					  . '</span>' : '';
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 *    telephone
267
+	 *    The telephone number.
268
+	 *
269
+	 * @access public
270
+	 * @param string $phone_nmbr
271
+	 * @return string
272
+	 */
273
+	public static function telephone($phone_nmbr = null)
274
+	{
275
+		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
276
+			: '';
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 *    URL
283
+	 *    URL of the item as a clickable link
284
+	 *
285
+	 * @access public
286
+	 * @param string $url        - the URL that the link will resolve to
287
+	 * @param string $text       - the text that will be used for the visible link
288
+	 * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
289
+	 * @return string (link)
290
+	 */
291
+	public static function url($url = null, $text = null, $attributes = array())
292
+	{
293
+		// Check the URL includes a scheme
294
+		$parsed_url = parse_url($url);
295
+		if (empty($parsed_url['scheme'])) {
296
+			$url = 'http://' . ltrim($url, '/');
297
+		}
298
+
299
+		$atts = '';
300
+		foreach ($attributes as $attribute => $value) {
301
+			$atts .= ' ' . $attribute . '="' . $value . '"';
302
+		}
303
+		$text = $text !== null && $text !== '' ? $text : $url;
304
+		return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>'
305
+			: '';
306
+	}
307 307
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     public static function add_json_linked_data_for_event(EE_Event $event)
22 22
     {
23 23
         // Check we have a valid datetime for the event
24
-        if (! $event->primary_datetime() instanceof EE_Datetime) {
24
+        if ( ! $event->primary_datetime() instanceof EE_Datetime) {
25 25
             return;
26 26
         }
27 27
 
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
                 $event_status = 'EventScheduled';
62 62
         }
63 63
         $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode';
64
-        $template_args['event_status'] = '"https://schema.org/' . $event_status . '"';
64
+        $template_args['event_status'] = '"https://schema.org/'.$event_status.'"';
65 65
         $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
66 66
         foreach ($event->tickets() as $original_ticket) {
67 67
             // clone tickets so that date formats don't override those for the original ticket
68
-            $ticket= clone $original_ticket;
68
+            $ticket = clone $original_ticket;
69 69
             $ID = $ticket->ID();
70
-            $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
-            $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
-            $template_args['event_tickets'][ $ID ]['price'] = number_format(
70
+            $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
+            $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
+            $template_args['event_tickets'][$ID]['price'] = number_format(
73 73
                 $ticket->price(),
74 74
                 EE_Registry::instance()->CFG->currency->dec_plc,
75 75
                 EE_Registry::instance()->CFG->currency->dec_mrk,
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
                     $availability = null;
87 87
                     break;
88 88
             }
89
-            $template_args['event_tickets'][ $ID ]['availability'] = $availability;
89
+            $template_args['event_tickets'][$ID]['availability'] = $availability;
90 90
             unset($ticket);
91 91
         }
92 92
         $VNU_ID = espresso_venue_id();
93
-        if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
93
+        if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
94 94
             $venue = EEH_Venue_View::get_venue($VNU_ID);
95 95
             $template_args['venue_name'] = get_the_title($VNU_ID);
96 96
             $template_args['venue_url'] = get_permalink($VNU_ID);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
             $VNU_ID
113 113
         );
114 114
         extract($template_args, EXTR_OVERWRITE);
115
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
115
+        include EE_TEMPLATES.'json_linked_data_for_event.template.php';
116 116
     }
117 117
 
118 118
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public static function name($name = null)
146 146
     {
147
-        return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : '';
147
+        return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : '';
148 148
     }
149 149
 
150 150
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     public static function streetAddress(EEI_Address $obj_with_address = null)
161 161
     {
162 162
         return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
163
-            ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
163
+            ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : '';
164 164
     }
165 165
 
166 166
 
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
         if (preg_match(
180 180
             "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
181 181
             $obj_with_address->address2()
182
-        ) ) {
182
+        )) {
183 183
             return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
184
-                ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
184
+                ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : '';
185 185
         } else {
186 186
             return $obj_with_address->address2();
187 187
         }
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     public static function addressLocality(EEI_Address $obj_with_address = null)
201 201
     {
202 202
         return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
203
-            ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
203
+            ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : '';
204 204
     }
205 205
 
206 206
 
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
     public static function addressRegion(EEI_Address $obj_with_address = null)
217 217
     {
218 218
         $state = $obj_with_address->state_name();
219
-        if (! empty($state)) {
220
-            return '<span itemprop="addressRegion">' . $state . '</span>';
219
+        if ( ! empty($state)) {
220
+            return '<span itemprop="addressRegion">'.$state.'</span>';
221 221
         } else {
222 222
             return '';
223 223
         }
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
     public static function addressCountry(EEI_Address $obj_with_address = null)
237 237
     {
238 238
         $country = $obj_with_address->country_name();
239
-        if (! empty($country)) {
240
-            return '<span itemprop="addressCountry">' . $country . '</span>';
239
+        if ( ! empty($country)) {
240
+            return '<span itemprop="addressCountry">'.$country.'</span>';
241 241
         } else {
242 242
             return '';
243 243
         }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      */
273 273
     public static function telephone($phone_nmbr = null)
274 274
     {
275
-        return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
275
+        return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>'
276 276
             : '';
277 277
     }
278 278
 
@@ -293,15 +293,15 @@  discard block
 block discarded – undo
293 293
         // Check the URL includes a scheme
294 294
         $parsed_url = parse_url($url);
295 295
         if (empty($parsed_url['scheme'])) {
296
-            $url = 'http://' . ltrim($url, '/');
296
+            $url = 'http://'.ltrim($url, '/');
297 297
         }
298 298
 
299 299
         $atts = '';
300 300
         foreach ($attributes as $attribute => $value) {
301
-            $atts .= ' ' . $attribute . '="' . $value . '"';
301
+            $atts .= ' '.$attribute.'="'.$value.'"';
302 302
         }
303 303
         $text = $text !== null && $text !== '' ? $text : $url;
304
-        return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>'
304
+        return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>'
305 305
             : '';
306 306
     }
307 307
 }
Please login to merge, or discard this patch.
core/templates/json_linked_data_for_event.template.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
   "eventStatus": [ <?php echo $event_status; ?> ],
29 29
   "offers": [
30 30
     <?php
31
-    $i = 0;
32
-    foreach ($event_tickets as $ticket) {?>
31
+	$i = 0;
32
+	foreach ($event_tickets as $ticket) {?>
33 33
     {
34 34
       "@type": "Offer",
35 35
       "url": "<?php echo $event_permalink; ?>",
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
38 38
       "price": "<?php echo $ticket['price']; ?>",
39 39
       "priceCurrency": "<?php echo $currency; ?>"
40 40
         <?php if (isset($ticket['availability'])) {
41
-            ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>"
41
+			?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>"
42 42
         <?php } ?>
43 43
     }<?php
44
-    $i++;
45
-    if ($i < count($event_tickets)) {
46
-        echo ',';
47
-    }
48
-    }
49
-    ?>
44
+	$i++;
45
+	if ($i < count($event_tickets)) {
46
+		echo ',';
47
+	}
48
+	}
49
+	?>
50 50
     ]<?php
51
-    if ($venue_name) {
52
-        ?>,
51
+	if ($venue_name) {
52
+		?>,
53 53
   "location": {
54 54
     "@type": "Place",
55 55
     "name": <?php echo wp_json_encode($venue_name); ?>,
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
     }
63 63
   }
64 64
     <?php
65
-    } ?>
65
+	} ?>
66 66
     <?php
67
-    if ($event_image) {
68
-        ?>,
67
+	if ($event_image) {
68
+		?>,
69 69
   "image": "<?php echo $event_image; ?>"
70 70
     <?php
71
-    } ?>
71
+	} ?>
72 72
     <?php do_action('AHEE__json_linked_data_for_event__template'); ?>
73 73
 }
74 74
 
Please login to merge, or discard this patch.
core/EE_Load_Textdomain.core.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
     {
37 37
         EE_Load_Textdomain::loadTranslationsForLocale();
38 38
         // now load the textdomain
39
-        if (!empty(EE_Load_Textdomain::$locale)) {
40
-            $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
39
+        if ( ! empty(EE_Load_Textdomain::$locale)) {
40
+            $github_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-'.EE_Load_Textdomain::$locale.'.mo';
41 41
             if (is_readable($github_mo_path)) {
42 42
                 load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
43 43
                 return;
44 44
             }
45
-            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
45
+            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-4-'.EE_Load_Textdomain::$locale.'.mo';
46 46
             if (is_readable($glotpress_mo_path)) {
47 47
                 load_textdomain('event_espresso', $glotpress_mo_path);
48 48
                 return;
49 49
             }
50 50
         }
51
-        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
51
+        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME).'/languages/');
52 52
     }
53 53
 
54 54
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         if (empty(EE_Load_Textdomain::$locale)) {
72 72
             return;
73 73
         }
74
-        $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
74
+        $language_check_option_name = 'ee_lang_check_'.EE_Load_Textdomain::$locale.'_'.EVENT_ESPRESSO_VERSION;
75 75
         // check if language files has already been sideloaded
76 76
         if (get_option($language_check_option_name)) {
77 77
             return;
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 
82 82
         // load sideloader and sideload the .POT file as this should always be included.
83 83
         $sideloader_args = array(
84
-            '_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
85
-            '_download_from'   => $repo_base_URL .'.pot?raw=true',
84
+            '_upload_to'     => EE_PLUGIN_DIR_PATH.'languages/',
85
+            '_download_from'   => $repo_base_URL.'.pot?raw=true',
86 86
             '_new_file_name' => 'event_espresso.pot',
87 87
         );
88 88
         /** @var EEH_Sideloader $sideloader */
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
             update_option($language_check_option_name, 1);
96 96
             return;
97 97
         }
98
-        $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
99
-        $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
98
+        $repo_locale_URL = $repo_base_URL.'-'.EE_Load_Textdomain::$locale;
99
+        $file_name_base = 'event_espresso-'.EE_Load_Textdomain::$locale;
100 100
 
101 101
         // made it here so let's get the language files from the github repo, first the .mo file
102 102
         $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
Please login to merge, or discard this patch.
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -13,105 +13,105 @@
 block discarded – undo
13 13
 class EE_Load_Textdomain extends EE_Base
14 14
 {
15 15
 
16
-    /**
17
-     * holds the current lang in WP
18
-     *
19
-     * @var string
20
-     */
21
-    private static $locale;
16
+	/**
17
+	 * holds the current lang in WP
18
+	 *
19
+	 * @var string
20
+	 */
21
+	private static $locale;
22 22
 
23 23
 
24
-    /**
25
-     * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub
26
-     * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback
27
-     *
28
-     * @return void
29
-     * @throws EE_Error
30
-     * @throws InvalidArgumentException
31
-     * @throws ReflectionException
32
-     * @throws InvalidDataTypeException
33
-     * @throws InvalidInterfaceException
34
-     */
35
-    public static function load_textdomain()
36
-    {
37
-        EE_Load_Textdomain::loadTranslationsForLocale();
38
-        // now load the textdomain
39
-        if (!empty(EE_Load_Textdomain::$locale)) {
40
-            $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
41
-            if (is_readable($github_mo_path)) {
42
-                load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
43
-                return;
44
-            }
45
-            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
46
-            if (is_readable($glotpress_mo_path)) {
47
-                load_textdomain('event_espresso', $glotpress_mo_path);
48
-                return;
49
-            }
50
-        }
51
-        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
52
-    }
24
+	/**
25
+	 * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub
26
+	 * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback
27
+	 *
28
+	 * @return void
29
+	 * @throws EE_Error
30
+	 * @throws InvalidArgumentException
31
+	 * @throws ReflectionException
32
+	 * @throws InvalidDataTypeException
33
+	 * @throws InvalidInterfaceException
34
+	 */
35
+	public static function load_textdomain()
36
+	{
37
+		EE_Load_Textdomain::loadTranslationsForLocale();
38
+		// now load the textdomain
39
+		if (!empty(EE_Load_Textdomain::$locale)) {
40
+			$github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
41
+			if (is_readable($github_mo_path)) {
42
+				load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
43
+				return;
44
+			}
45
+			$glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
46
+			if (is_readable($glotpress_mo_path)) {
47
+				load_textdomain('event_espresso', $glotpress_mo_path);
48
+				return;
49
+			}
50
+		}
51
+		load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary).
57
-     *
58
-     * @access private
59
-     * @static
60
-     * @return void
61
-     * @throws EE_Error
62
-     * @throws InvalidArgumentException
63
-     * @throws ReflectionException
64
-     * @throws InvalidDataTypeException
65
-     * @throws InvalidInterfaceException
66
-     */
67
-    private static function loadTranslationsForLocale()
68
-    {
69
-        EE_Load_Textdomain::$locale = get_locale();
70
-        // can't download a language file if a language isn't set <taps temple>
71
-        if (empty(EE_Load_Textdomain::$locale)) {
72
-            return;
73
-        }
74
-        $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
75
-        // check if language files has already been sideloaded
76
-        if (get_option($language_check_option_name)) {
77
-            return;
78
-        }
55
+	/**
56
+	 * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary).
57
+	 *
58
+	 * @access private
59
+	 * @static
60
+	 * @return void
61
+	 * @throws EE_Error
62
+	 * @throws InvalidArgumentException
63
+	 * @throws ReflectionException
64
+	 * @throws InvalidDataTypeException
65
+	 * @throws InvalidInterfaceException
66
+	 */
67
+	private static function loadTranslationsForLocale()
68
+	{
69
+		EE_Load_Textdomain::$locale = get_locale();
70
+		// can't download a language file if a language isn't set <taps temple>
71
+		if (empty(EE_Load_Textdomain::$locale)) {
72
+			return;
73
+		}
74
+		$language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
75
+		// check if language files has already been sideloaded
76
+		if (get_option($language_check_option_name)) {
77
+			return;
78
+		}
79 79
 
80
-        $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
80
+		$repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
81 81
 
82
-        // load sideloader and sideload the .POT file as this should always be included.
83
-        $sideloader_args = array(
84
-            '_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
85
-            '_download_from'   => $repo_base_URL .'.pot?raw=true',
86
-            '_new_file_name' => 'event_espresso.pot',
87
-        );
88
-        /** @var EEH_Sideloader $sideloader */
89
-        $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false);
90
-        // sideload the .POT file only for main site of the network, or if not running Multisite.
91
-        if (is_main_site()) {
92
-            $sideloader->sideload();
93
-        }
82
+		// load sideloader and sideload the .POT file as this should always be included.
83
+		$sideloader_args = array(
84
+			'_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
85
+			'_download_from'   => $repo_base_URL .'.pot?raw=true',
86
+			'_new_file_name' => 'event_espresso.pot',
87
+		);
88
+		/** @var EEH_Sideloader $sideloader */
89
+		$sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false);
90
+		// sideload the .POT file only for main site of the network, or if not running Multisite.
91
+		if (is_main_site()) {
92
+			$sideloader->sideload();
93
+		}
94 94
 
95
-        // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US"
96
-        if (EE_Load_Textdomain::$locale === 'en_US') {
97
-            // but set option first else we'll forever be downloading the pot file
98
-            update_option($language_check_option_name, 1);
99
-            return;
100
-        }
101
-        $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
102
-        $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
95
+		// if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US"
96
+		if (EE_Load_Textdomain::$locale === 'en_US') {
97
+			// but set option first else we'll forever be downloading the pot file
98
+			update_option($language_check_option_name, 1);
99
+			return;
100
+		}
101
+		$repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
102
+		$file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
103 103
 
104
-        // made it here so let's get the language files from the github repo, first the .mo file
105
-        $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
106
-        $sideloader->set_new_file_name("{$file_name_base}.mo");
107
-        $sideloader->sideload();
104
+		// made it here so let's get the language files from the github repo, first the .mo file
105
+		$sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
106
+		$sideloader->set_new_file_name("{$file_name_base}.mo");
107
+		$sideloader->sideload();
108 108
 
109
-        // now the .po file:
110
-        $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true");
111
-        $sideloader->set_new_file_name("{$file_name_base}.po");
112
-        $sideloader->sideload();
109
+		// now the .po file:
110
+		$sideloader->set_download_from("{$repo_locale_URL}.po?raw=true");
111
+		$sideloader->set_new_file_name("{$file_name_base}.po");
112
+		$sideloader->sideload();
113 113
 
114
-        // set option so the above only runs when EE updates.
115
-        update_option($language_check_option_name, 1);
116
-    }
114
+		// set option so the above only runs when EE updates.
115
+		update_option($language_check_option_name, 1);
116
+	}
117 117
 }
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 1 patch
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -33,725 +33,725 @@
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     * @var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     * @var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-    /**
69
-     * @var boolean $display_full_ui
70
-     */
71
-    private $display_full_ui;
72
-
73
-
74
-    /**
75
-     * DisplayTicketSelector constructor.
76
-     *
77
-     * @param bool $iframe
78
-     */
79
-    public function __construct($iframe = false)
80
-    {
81
-        $this->iframe = $iframe;
82
-        $this->date_format = apply_filters(
83
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
-            get_option('date_format')
85
-        );
86
-        $this->time_format = apply_filters(
87
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
-            get_option('time_format')
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @return bool
95
-     */
96
-    public function isIframe()
97
-    {
98
-        return $this->iframe;
99
-    }
100
-
101
-
102
-    /**
103
-     * @param boolean $iframe
104
-     */
105
-    public function setIframe($iframe = true)
106
-    {
107
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
-    }
109
-
110
-
111
-    /**
112
-     * finds and sets the \EE_Event object for use throughout class
113
-     *
114
-     * @param mixed $event
115
-     * @return bool
116
-     * @throws EE_Error
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidInterfaceException
119
-     * @throws InvalidArgumentException
120
-     */
121
-    protected function setEvent($event = null)
122
-    {
123
-        if ($event === null) {
124
-            global $post;
125
-            $event = $post;
126
-        }
127
-        if ($event instanceof EE_Event) {
128
-            $this->event = $event;
129
-        } elseif ($event instanceof WP_Post) {
130
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
-                $this->event = $event->EE_Event;
132
-            } elseif ($event->post_type === 'espresso_events') {
133
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
-                $this->event = $event->EE_Event;
135
-            }
136
-        } else {
137
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
-            $dev_msg = $user_msg . __(
139
-                'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
-                'event_espresso'
141
-            );
142
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        return true;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return int
151
-     */
152
-    public function getMaxAttendees()
153
-    {
154
-        return $this->max_attendees;
155
-    }
156
-
157
-
158
-    /**
159
-     * @param int $max_attendees
160
-     */
161
-    public function setMaxAttendees($max_attendees)
162
-    {
163
-        $this->max_attendees = absint(
164
-            apply_filters(
165
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
-                $max_attendees
167
-            )
168
-        );
169
-    }
170
-
171
-
172
-    /**
173
-     * Returns whether or not the full ticket selector should be shown or not.
174
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
175
-     *
176
-     * @return bool
177
-     */
178
-    private function display_full_ui()
179
-    {
180
-        if ($this->display_full_ui === null) {
181
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
-        }
183
-        return $this->display_full_ui;
184
-    }
185
-
186
-
187
-    /**
188
-     * creates buttons for selecting number of attendees for an event
189
-     *
190
-     * @param WP_Post|int $event
191
-     * @param bool        $view_details
192
-     * @return string
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     */
198
-    public function display($event = null, $view_details = false)
199
-    {
200
-        // reset filter for displaying submit button
201
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
-        // poke and prod incoming event till it tells us what it is
203
-        if (! $this->setEvent($event)) {
204
-            return false;
205
-        }
206
-        // begin gathering template arguments by getting event status
207
-        $template_args = array('event_status' => $this->event->get_active_status());
208
-        if ($this->activeEventAndShowTicketSelector(
209
-            $event,
210
-            $template_args['event_status'],
211
-            $view_details
212
-        )) {
213
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
214
-        }
215
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
216
-        $this->setMaxAttendees($this->event->additional_limit());
217
-        if ($this->getMaxAttendees() < 1) {
218
-            return $this->ticketSalesClosedMessage();
219
-        }
220
-        // is the event expired ?
221
-        $template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false;
222
-        if ($template_args['event_is_expired']) {
223
-            return $this->expiredEventMessage();
224
-        }
225
-        // get all tickets for this event ordered by the datetime
226
-        $tickets = $this->getTickets();
227
-        if (count($tickets) < 1) {
228
-            return $this->noTicketAvailableMessage();
229
-        }
230
-        // redirecting to another site for registration ??
231
-        $external_url = (string) $this->event->external_url()
232
-            && $this->event->external_url() !== get_the_permalink()
233
-            ? $this->event->external_url()
234
-            : '';
235
-        // if redirecting to another site for registration, then we don't load the TS
236
-        $ticket_selector = $external_url
237
-            ? $this->externalEventRegistration()
238
-            : $this->loadTicketSelector($tickets, $template_args);
239
-        // now set up the form (but not for the admin)
240
-        $ticket_selector = $this->display_full_ui()
241
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
242
-            : $ticket_selector;
243
-        // submit button and form close tag
244
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
245
-        return $ticket_selector;
246
-    }
247
-
248
-
249
-    /**
250
-     * displayTicketSelector
251
-     * examines the event properties and determines whether a Ticket Selector should be displayed
252
-     *
253
-     * @param WP_Post|int $event
254
-     * @param string      $_event_active_status
255
-     * @param bool        $view_details
256
-     * @return bool
257
-     * @throws EE_Error
258
-     */
259
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
260
-    {
261
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
262
-        return $this->display_full_ui()
263
-               && (
264
-                   ! $this->event->display_ticket_selector()
265
-                   || $view_details
266
-                   || post_password_required($event_post)
267
-                   || (
268
-                       $_event_active_status !== EE_Datetime::active
269
-                       && $_event_active_status !== EE_Datetime::upcoming
270
-                       && $_event_active_status !== EE_Datetime::sold_out
271
-                       && ! (
272
-                           $_event_active_status === EE_Datetime::inactive
273
-                           && is_user_logged_in()
274
-                       )
275
-                   )
276
-               );
277
-    }
278
-
279
-
280
-    /**
281
-     * noTicketAvailableMessage
282
-     * notice displayed if event is expired
283
-     *
284
-     * @return string
285
-     * @throws EE_Error
286
-     */
287
-    protected function expiredEventMessage()
288
-    {
289
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
290
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
291
-            'event_espresso'
292
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
293
-    }
294
-
295
-
296
-    /**
297
-     * noTicketAvailableMessage
298
-     * notice displayed if event has no more tickets available
299
-     *
300
-     * @return string
301
-     * @throws EE_Error
302
-     */
303
-    protected function noTicketAvailableMessage()
304
-    {
305
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
306
-        if (current_user_can('edit_post', $this->event->ID())) {
307
-            $no_ticket_available_msg .= sprintf(
308
-                esc_html__(
309
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
310
-                    'event_espresso'
311
-                ),
312
-                '<div class="ee-attention" style="text-align: left;"><b>',
313
-                '</b><br />',
314
-                '<span class="edit-link"><a class="post-edit-link" href="'
315
-                . get_edit_post_link($this->event->ID())
316
-                . '">',
317
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
318
-            );
319
-        }
320
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 * @var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 * @var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+	/**
69
+	 * @var boolean $display_full_ui
70
+	 */
71
+	private $display_full_ui;
72
+
73
+
74
+	/**
75
+	 * DisplayTicketSelector constructor.
76
+	 *
77
+	 * @param bool $iframe
78
+	 */
79
+	public function __construct($iframe = false)
80
+	{
81
+		$this->iframe = $iframe;
82
+		$this->date_format = apply_filters(
83
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
+			get_option('date_format')
85
+		);
86
+		$this->time_format = apply_filters(
87
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
+			get_option('time_format')
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return bool
95
+	 */
96
+	public function isIframe()
97
+	{
98
+		return $this->iframe;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param boolean $iframe
104
+	 */
105
+	public function setIframe($iframe = true)
106
+	{
107
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
+	}
109
+
110
+
111
+	/**
112
+	 * finds and sets the \EE_Event object for use throughout class
113
+	 *
114
+	 * @param mixed $event
115
+	 * @return bool
116
+	 * @throws EE_Error
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidInterfaceException
119
+	 * @throws InvalidArgumentException
120
+	 */
121
+	protected function setEvent($event = null)
122
+	{
123
+		if ($event === null) {
124
+			global $post;
125
+			$event = $post;
126
+		}
127
+		if ($event instanceof EE_Event) {
128
+			$this->event = $event;
129
+		} elseif ($event instanceof WP_Post) {
130
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
+				$this->event = $event->EE_Event;
132
+			} elseif ($event->post_type === 'espresso_events') {
133
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
+				$this->event = $event->EE_Event;
135
+			}
136
+		} else {
137
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
+			$dev_msg = $user_msg . __(
139
+				'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
+				'event_espresso'
141
+			);
142
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		return true;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return int
151
+	 */
152
+	public function getMaxAttendees()
153
+	{
154
+		return $this->max_attendees;
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param int $max_attendees
160
+	 */
161
+	public function setMaxAttendees($max_attendees)
162
+	{
163
+		$this->max_attendees = absint(
164
+			apply_filters(
165
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
+				$max_attendees
167
+			)
168
+		);
169
+	}
170
+
171
+
172
+	/**
173
+	 * Returns whether or not the full ticket selector should be shown or not.
174
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
175
+	 *
176
+	 * @return bool
177
+	 */
178
+	private function display_full_ui()
179
+	{
180
+		if ($this->display_full_ui === null) {
181
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
+		}
183
+		return $this->display_full_ui;
184
+	}
185
+
186
+
187
+	/**
188
+	 * creates buttons for selecting number of attendees for an event
189
+	 *
190
+	 * @param WP_Post|int $event
191
+	 * @param bool        $view_details
192
+	 * @return string
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 */
198
+	public function display($event = null, $view_details = false)
199
+	{
200
+		// reset filter for displaying submit button
201
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
+		// poke and prod incoming event till it tells us what it is
203
+		if (! $this->setEvent($event)) {
204
+			return false;
205
+		}
206
+		// begin gathering template arguments by getting event status
207
+		$template_args = array('event_status' => $this->event->get_active_status());
208
+		if ($this->activeEventAndShowTicketSelector(
209
+			$event,
210
+			$template_args['event_status'],
211
+			$view_details
212
+		)) {
213
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
214
+		}
215
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
216
+		$this->setMaxAttendees($this->event->additional_limit());
217
+		if ($this->getMaxAttendees() < 1) {
218
+			return $this->ticketSalesClosedMessage();
219
+		}
220
+		// is the event expired ?
221
+		$template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false;
222
+		if ($template_args['event_is_expired']) {
223
+			return $this->expiredEventMessage();
224
+		}
225
+		// get all tickets for this event ordered by the datetime
226
+		$tickets = $this->getTickets();
227
+		if (count($tickets) < 1) {
228
+			return $this->noTicketAvailableMessage();
229
+		}
230
+		// redirecting to another site for registration ??
231
+		$external_url = (string) $this->event->external_url()
232
+			&& $this->event->external_url() !== get_the_permalink()
233
+			? $this->event->external_url()
234
+			: '';
235
+		// if redirecting to another site for registration, then we don't load the TS
236
+		$ticket_selector = $external_url
237
+			? $this->externalEventRegistration()
238
+			: $this->loadTicketSelector($tickets, $template_args);
239
+		// now set up the form (but not for the admin)
240
+		$ticket_selector = $this->display_full_ui()
241
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
242
+			: $ticket_selector;
243
+		// submit button and form close tag
244
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
245
+		return $ticket_selector;
246
+	}
247
+
248
+
249
+	/**
250
+	 * displayTicketSelector
251
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
252
+	 *
253
+	 * @param WP_Post|int $event
254
+	 * @param string      $_event_active_status
255
+	 * @param bool        $view_details
256
+	 * @return bool
257
+	 * @throws EE_Error
258
+	 */
259
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
260
+	{
261
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
262
+		return $this->display_full_ui()
263
+			   && (
264
+				   ! $this->event->display_ticket_selector()
265
+				   || $view_details
266
+				   || post_password_required($event_post)
267
+				   || (
268
+					   $_event_active_status !== EE_Datetime::active
269
+					   && $_event_active_status !== EE_Datetime::upcoming
270
+					   && $_event_active_status !== EE_Datetime::sold_out
271
+					   && ! (
272
+						   $_event_active_status === EE_Datetime::inactive
273
+						   && is_user_logged_in()
274
+					   )
275
+				   )
276
+			   );
277
+	}
278
+
279
+
280
+	/**
281
+	 * noTicketAvailableMessage
282
+	 * notice displayed if event is expired
283
+	 *
284
+	 * @return string
285
+	 * @throws EE_Error
286
+	 */
287
+	protected function expiredEventMessage()
288
+	{
289
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
290
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
291
+			'event_espresso'
292
+		) . '</span></div><!-- .ee-event-expired-notice -->';
293
+	}
294
+
295
+
296
+	/**
297
+	 * noTicketAvailableMessage
298
+	 * notice displayed if event has no more tickets available
299
+	 *
300
+	 * @return string
301
+	 * @throws EE_Error
302
+	 */
303
+	protected function noTicketAvailableMessage()
304
+	{
305
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
306
+		if (current_user_can('edit_post', $this->event->ID())) {
307
+			$no_ticket_available_msg .= sprintf(
308
+				esc_html__(
309
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
310
+					'event_espresso'
311
+				),
312
+				'<div class="ee-attention" style="text-align: left;"><b>',
313
+				'</b><br />',
314
+				'<span class="edit-link"><a class="post-edit-link" href="'
315
+				. get_edit_post_link($this->event->ID())
316
+				. '">',
317
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
318
+			);
319
+		}
320
+		return '
321 321
             <div class="ee-event-expired-notice">
322 322
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
323 323
             </div><!-- .ee-event-expired-notice -->';
324
-    }
325
-
326
-
327
-    /**
328
-     * ticketSalesClosed
329
-     * notice displayed if event ticket sales are turned off
330
-     *
331
-     * @return string
332
-     * @throws EE_Error
333
-     */
334
-    protected function ticketSalesClosedMessage()
335
-    {
336
-        $sales_closed_msg = esc_html__(
337
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
338
-            'event_espresso'
339
-        );
340
-        if (current_user_can('edit_post', $this->event->ID())) {
341
-            $sales_closed_msg .= sprintf(
342
-                esc_html__(
343
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
344
-                    'event_espresso'
345
-                ),
346
-                '<div class="ee-attention" style="text-align: left;"><b>',
347
-                '</b><br />',
348
-                '<span class="edit-link"><a class="post-edit-link" href="'
349
-                . get_edit_post_link($this->event->ID())
350
-                . '">',
351
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352
-            );
353
-        }
354
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
355
-    }
356
-
357
-
358
-    /**
359
-     * getTickets
360
-     *
361
-     * @return \EE_Base_Class[]|\EE_Ticket[]
362
-     * @throws EE_Error
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidInterfaceException
365
-     * @throws InvalidArgumentException
366
-     */
367
-    protected function getTickets()
368
-    {
369
-        $show_expired_tickets = is_admin() || (
370
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
371
-            && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
372
-        );
373
-
374
-        $ticket_query_args = array(
375
-            array('Datetime.EVT_ID' => $this->event->ID()),
376
-            'order_by' => array(
377
-                'TKT_order'              => 'ASC',
378
-                'TKT_required'           => 'DESC',
379
-                'TKT_start_date'         => 'ASC',
380
-                'TKT_end_date'           => 'ASC',
381
-                'Datetime.DTT_EVT_start' => 'DESC',
382
-            ),
383
-        );
384
-        if (! $show_expired_tickets) {
385
-            // use the correct applicable time query depending on what version of core is being run.
386
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387
-                ? time()
388
-                : current_time('timestamp');
389
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
390
-        }
391
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
392
-    }
393
-
394
-
395
-    /**
396
-     * loadTicketSelector
397
-     * begins to assemble template arguments
398
-     * and decides whether to load a "simple" ticket selector, or the standard
399
-     *
400
-     * @param \EE_Ticket[] $tickets
401
-     * @param array        $template_args
402
-     * @return string
403
-     * @throws EE_Error
404
-     */
405
-    protected function loadTicketSelector(array $tickets, array $template_args)
406
-    {
407
-        $template_args['event'] = $this->event;
408
-        $template_args['EVT_ID'] = $this->event->ID();
409
-        $template_args['event_is_expired'] = $this->event->is_expired();
410
-        $template_args['max_atndz'] = $this->getMaxAttendees();
411
-        $template_args['date_format'] = $this->date_format;
412
-        $template_args['time_format'] = $this->time_format;
413
-        /**
414
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
415
-         *
416
-         * @since 4.9.13
417
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
418
-         * @param int $EVT_ID The Event ID
419
-         */
420
-        $template_args['anchor_id'] = apply_filters(
421
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
-            '#tkt-slctr-tbl-' . $this->event->ID(),
423
-            $this->event->ID()
424
-        );
425
-        $template_args['tickets'] = $tickets;
426
-        $template_args['ticket_count'] = count($tickets);
427
-        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
428
-        return $ticket_selector instanceof TicketSelectorSimple
429
-            ? $ticket_selector
430
-            : new TicketSelectorStandard(
431
-                $this->event,
432
-                $tickets,
433
-                $this->getMaxAttendees(),
434
-                $template_args,
435
-                $this->date_format,
436
-                $this->time_format
437
-            );
438
-    }
439
-
440
-
441
-    /**
442
-     * simpleTicketSelector
443
-     * there's one ticket, and max attendees is set to one,
444
-     * so if the event is free, then this is a "simple" ticket selector
445
-     * a.k.a. "Dude Where's my Ticket Selector?"
446
-     *
447
-     * @param \EE_Ticket[] $tickets
448
-     * @param array        $template_args
449
-     * @return string
450
-     * @throws EE_Error
451
-     */
452
-    protected function simpleTicketSelector($tickets, array $template_args)
453
-    {
454
-        // if there is only ONE ticket with a max qty of ONE
455
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
456
-            return '';
457
-        }
458
-        /** @var \EE_Ticket $ticket */
459
-        $ticket = reset($tickets);
460
-        // if the ticket is free... then not much need for the ticket selector
461
-        if (apply_filters(
462
-            'FHEE__ticket_selector_chart_template__hide_ticket_selector',
463
-            $ticket->is_free(),
464
-            $this->event->ID()
465
-        )) {
466
-            return new TicketSelectorSimple(
467
-                $this->event,
468
-                $ticket,
469
-                $this->getMaxAttendees(),
470
-                $template_args
471
-            );
472
-        }
473
-        return '';
474
-    }
475
-
476
-
477
-    /**
478
-     * externalEventRegistration
479
-     *
480
-     * @return string
481
-     */
482
-    public function externalEventRegistration()
483
-    {
484
-        // if not we still need to trigger the display of the submit button
485
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
486
-        // display notice to admin that registration is external
487
-        return $this->display_full_ui()
488
-            ? esc_html__(
489
-                'Registration is at an external URL for this event.',
490
-                'event_espresso'
491
-            )
492
-            : '';
493
-    }
494
-
495
-
496
-    /**
497
-     * formOpen
498
-     *
499
-     * @param        int    $ID
500
-     * @param        string $external_url
501
-     * @return        string
502
-     */
503
-    public function formOpen($ID = 0, $external_url = '')
504
-    {
505
-        // if redirecting, we don't need any anything else
506
-        if ($external_url) {
507
-            $html = '<form method="GET" ';
508
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
510
-            // open link in new window ?
511
-            $html .= apply_filters(
512
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
513
-                $this->isIframe(),
514
-                $this
515
-            )
516
-                ? ' target="_blank"'
517
-                : '';
518
-            $html .= '>';
519
-            $query_args = EEH_URL::get_query_string($external_url);
520
-            foreach ((array) $query_args as $query_arg => $value) {
521
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
522
-            }
523
-            return $html;
524
-        }
525
-        // if there is no submit button, then don't start building a form
526
-        // because the "View Details" button will build its own form
527
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
-            return '';
529
-        }
530
-        $checkout_url = EEH_Event_View::event_link_url($ID);
531
-        if (! $checkout_url) {
532
-            EE_Error::add_error(
533
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534
-                __FILE__,
535
-                __FUNCTION__,
536
-                __LINE__
537
-            );
538
-        }
539
-        // set no cache headers and constants
540
-        EE_System::do_not_cache();
541
-        $html = '<form method="POST" ';
542
-        $html .= 'action="' . $checkout_url . '" ';
543
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
544
-        $html .= $this->iframe ? ' target="_blank"' : '';
545
-        $html .= '>';
546
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
547
-        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
548
-        return $html;
549
-    }
550
-
551
-
552
-    /**
553
-     * displaySubmitButton
554
-     *
555
-     * @param  string $external_url
556
-     * @return string
557
-     * @throws EE_Error
558
-     */
559
-    public function displaySubmitButton($external_url = '')
560
-    {
561
-        $html = '';
562
-        if ($this->display_full_ui()) {
563
-            // standard TS displayed with submit button, ie: "Register Now"
564
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
565
-                $html .= $this->displayRegisterNowButton();
566
-                $html .= empty($external_url)
567
-                    ? $this->ticketSelectorEndDiv()
568
-                    : $this->clearTicketSelector();
569
-                $html .= '<br/>' . $this->formClose();
570
-            } elseif ($this->getMaxAttendees() === 1) {
571
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572
-                if ($this->event->is_sold_out()) {
573
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
574
-                    $html .= apply_filters(
575
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
576
-                        sprintf(
577
-                            __(
578
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
579
-                                'event_espresso'
580
-                            ),
581
-                            '<p class="no-ticket-selector-msg clear-float">',
582
-                            $this->event->name(),
583
-                            '</p>',
584
-                            '<br />'
585
-                        ),
586
-                        $this->event
587
-                    );
588
-                    if (apply_filters(
589
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
590
-                        false,
591
-                        $this->event
592
-                    )) {
593
-                        $html .= $this->displayRegisterNowButton();
594
-                    }
595
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
596
-                    $html .= $this->ticketSelectorEndDiv();
597
-                } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
598
-                          && ! is_single()
599
-                ) {
600
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
601
-                    // but no tickets are available, so display event's "View Details" button.
602
-                    // it is being viewed via somewhere other than a single post
603
-                    $html .= $this->displayViewDetailsButton(true);
604
-                } else {
605
-                    $html .= $this->ticketSelectorEndDiv();
606
-                }
607
-            } elseif (is_archive()) {
608
-                // event list, no tickets available so display event's "View Details" button
609
-                $html .= $this->ticketSelectorEndDiv();
610
-                $html .= $this->displayViewDetailsButton();
611
-            } else {
612
-                if (apply_filters(
613
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
614
-                    false,
615
-                    $this->event
616
-                )) {
617
-                    $html .= $this->displayRegisterNowButton();
618
-                }
619
-                // no submit or view details button, and no additional content
620
-                $html .= $this->ticketSelectorEndDiv();
621
-            }
622
-            if (! $this->iframe && ! is_archive()) {
623
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624
-            }
625
-        }
626
-        return apply_filters(
627
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
628
-            $html,
629
-            $this->event,
630
-            $this
631
-        );
632
-    }
633
-
634
-
635
-    /**
636
-     * @return string
637
-     * @throws EE_Error
638
-     */
639
-    public function displayRegisterNowButton()
640
-    {
641
-        $btn_text = apply_filters(
642
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
643
-            __('Register Now', 'event_espresso'),
644
-            $this->event
645
-        );
646
-        $external_url = (string) $this->event->external_url()
647
-            && $this->event->external_url() !== get_the_permalink()
648
-            ? $this->event->external_url()
649
-            : '';
650
-        $html = EEH_HTML::div(
651
-            '',
652
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
653
-            'ticket-selector-submit-btn-wrap'
654
-        );
655
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
656
-        $html .= ' class="ticket-selector-submit-btn ';
657
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
-        $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
660
-        $html .= apply_filters(
661
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662
-            '',
663
-            $this->event,
664
-            $this->iframe
665
-        );
666
-        return $html;
667
-    }
668
-
669
-
670
-    /**
671
-     * displayViewDetailsButton
672
-     *
673
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
674
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
675
-     *                    either because they are sold out, expired, or not yet on sale.
676
-     *                    In this case, we need to close the form BEFORE adding any closing divs
677
-     * @return string
678
-     * @throws EE_Error
679
-     */
680
-    public function displayViewDetailsButton($DWMTS = false)
681
-    {
682
-        if (! $this->event->get_permalink()) {
683
-            EE_Error::add_error(
684
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685
-                __FILE__,
686
-                __FUNCTION__,
687
-                __LINE__
688
-            );
689
-        }
690
-        $view_details_btn = '<form method="GET" action="';
691
-        $view_details_btn .= apply_filters(
692
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
693
-            $this->event->get_permalink(),
694
-            $this->event
695
-        );
696
-        $view_details_btn .= '"';
697
-        // open link in new window ?
698
-        $view_details_btn .= apply_filters(
699
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
700
-            $this->isIframe(),
701
-            $this
702
-        )
703
-            ? ' target="_blank"'
704
-            : '';
705
-        $view_details_btn .= '>';
706
-        $btn_text = apply_filters(
707
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
708
-            esc_html__('View Details', 'event_espresso'),
709
-            $this->event
710
-        );
711
-        $view_details_btn .= '<input id="ticket-selector-submit-'
712
-                             . $this->event->ID()
713
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
714
-                             . $btn_text
715
-                             . '" />';
716
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
717
-        if ($DWMTS) {
718
-            $view_details_btn .= $this->formClose();
719
-            $view_details_btn .= $this->ticketSelectorEndDiv();
720
-            $view_details_btn .= '<br/>';
721
-        } else {
722
-            $view_details_btn .= $this->clearTicketSelector();
723
-            $view_details_btn .= '<br/>';
724
-            $view_details_btn .= $this->formClose();
725
-        }
726
-        return $view_details_btn;
727
-    }
728
-
729
-
730
-    /**
731
-     * @return string
732
-     */
733
-    public function ticketSelectorEndDiv()
734
-    {
735
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
736
-    }
737
-
738
-
739
-    /**
740
-     * @return string
741
-     */
742
-    public function clearTicketSelector()
743
-    {
744
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
745
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
746
-    }
747
-
748
-
749
-    /**
750
-     * @access        public
751
-     * @return        string
752
-     */
753
-    public function formClose()
754
-    {
755
-        return '</form>';
756
-    }
324
+	}
325
+
326
+
327
+	/**
328
+	 * ticketSalesClosed
329
+	 * notice displayed if event ticket sales are turned off
330
+	 *
331
+	 * @return string
332
+	 * @throws EE_Error
333
+	 */
334
+	protected function ticketSalesClosedMessage()
335
+	{
336
+		$sales_closed_msg = esc_html__(
337
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
338
+			'event_espresso'
339
+		);
340
+		if (current_user_can('edit_post', $this->event->ID())) {
341
+			$sales_closed_msg .= sprintf(
342
+				esc_html__(
343
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
344
+					'event_espresso'
345
+				),
346
+				'<div class="ee-attention" style="text-align: left;"><b>',
347
+				'</b><br />',
348
+				'<span class="edit-link"><a class="post-edit-link" href="'
349
+				. get_edit_post_link($this->event->ID())
350
+				. '">',
351
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352
+			);
353
+		}
354
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
355
+	}
356
+
357
+
358
+	/**
359
+	 * getTickets
360
+	 *
361
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
362
+	 * @throws EE_Error
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidInterfaceException
365
+	 * @throws InvalidArgumentException
366
+	 */
367
+	protected function getTickets()
368
+	{
369
+		$show_expired_tickets = is_admin() || (
370
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
371
+			&& EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
372
+		);
373
+
374
+		$ticket_query_args = array(
375
+			array('Datetime.EVT_ID' => $this->event->ID()),
376
+			'order_by' => array(
377
+				'TKT_order'              => 'ASC',
378
+				'TKT_required'           => 'DESC',
379
+				'TKT_start_date'         => 'ASC',
380
+				'TKT_end_date'           => 'ASC',
381
+				'Datetime.DTT_EVT_start' => 'DESC',
382
+			),
383
+		);
384
+		if (! $show_expired_tickets) {
385
+			// use the correct applicable time query depending on what version of core is being run.
386
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387
+				? time()
388
+				: current_time('timestamp');
389
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
390
+		}
391
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
392
+	}
393
+
394
+
395
+	/**
396
+	 * loadTicketSelector
397
+	 * begins to assemble template arguments
398
+	 * and decides whether to load a "simple" ticket selector, or the standard
399
+	 *
400
+	 * @param \EE_Ticket[] $tickets
401
+	 * @param array        $template_args
402
+	 * @return string
403
+	 * @throws EE_Error
404
+	 */
405
+	protected function loadTicketSelector(array $tickets, array $template_args)
406
+	{
407
+		$template_args['event'] = $this->event;
408
+		$template_args['EVT_ID'] = $this->event->ID();
409
+		$template_args['event_is_expired'] = $this->event->is_expired();
410
+		$template_args['max_atndz'] = $this->getMaxAttendees();
411
+		$template_args['date_format'] = $this->date_format;
412
+		$template_args['time_format'] = $this->time_format;
413
+		/**
414
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
415
+		 *
416
+		 * @since 4.9.13
417
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
418
+		 * @param int $EVT_ID The Event ID
419
+		 */
420
+		$template_args['anchor_id'] = apply_filters(
421
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
+			'#tkt-slctr-tbl-' . $this->event->ID(),
423
+			$this->event->ID()
424
+		);
425
+		$template_args['tickets'] = $tickets;
426
+		$template_args['ticket_count'] = count($tickets);
427
+		$ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
428
+		return $ticket_selector instanceof TicketSelectorSimple
429
+			? $ticket_selector
430
+			: new TicketSelectorStandard(
431
+				$this->event,
432
+				$tickets,
433
+				$this->getMaxAttendees(),
434
+				$template_args,
435
+				$this->date_format,
436
+				$this->time_format
437
+			);
438
+	}
439
+
440
+
441
+	/**
442
+	 * simpleTicketSelector
443
+	 * there's one ticket, and max attendees is set to one,
444
+	 * so if the event is free, then this is a "simple" ticket selector
445
+	 * a.k.a. "Dude Where's my Ticket Selector?"
446
+	 *
447
+	 * @param \EE_Ticket[] $tickets
448
+	 * @param array        $template_args
449
+	 * @return string
450
+	 * @throws EE_Error
451
+	 */
452
+	protected function simpleTicketSelector($tickets, array $template_args)
453
+	{
454
+		// if there is only ONE ticket with a max qty of ONE
455
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
456
+			return '';
457
+		}
458
+		/** @var \EE_Ticket $ticket */
459
+		$ticket = reset($tickets);
460
+		// if the ticket is free... then not much need for the ticket selector
461
+		if (apply_filters(
462
+			'FHEE__ticket_selector_chart_template__hide_ticket_selector',
463
+			$ticket->is_free(),
464
+			$this->event->ID()
465
+		)) {
466
+			return new TicketSelectorSimple(
467
+				$this->event,
468
+				$ticket,
469
+				$this->getMaxAttendees(),
470
+				$template_args
471
+			);
472
+		}
473
+		return '';
474
+	}
475
+
476
+
477
+	/**
478
+	 * externalEventRegistration
479
+	 *
480
+	 * @return string
481
+	 */
482
+	public function externalEventRegistration()
483
+	{
484
+		// if not we still need to trigger the display of the submit button
485
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
486
+		// display notice to admin that registration is external
487
+		return $this->display_full_ui()
488
+			? esc_html__(
489
+				'Registration is at an external URL for this event.',
490
+				'event_espresso'
491
+			)
492
+			: '';
493
+	}
494
+
495
+
496
+	/**
497
+	 * formOpen
498
+	 *
499
+	 * @param        int    $ID
500
+	 * @param        string $external_url
501
+	 * @return        string
502
+	 */
503
+	public function formOpen($ID = 0, $external_url = '')
504
+	{
505
+		// if redirecting, we don't need any anything else
506
+		if ($external_url) {
507
+			$html = '<form method="GET" ';
508
+			$html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
+			$html .= 'name="ticket-selector-form-' . $ID . '"';
510
+			// open link in new window ?
511
+			$html .= apply_filters(
512
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
513
+				$this->isIframe(),
514
+				$this
515
+			)
516
+				? ' target="_blank"'
517
+				: '';
518
+			$html .= '>';
519
+			$query_args = EEH_URL::get_query_string($external_url);
520
+			foreach ((array) $query_args as $query_arg => $value) {
521
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
522
+			}
523
+			return $html;
524
+		}
525
+		// if there is no submit button, then don't start building a form
526
+		// because the "View Details" button will build its own form
527
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
+			return '';
529
+		}
530
+		$checkout_url = EEH_Event_View::event_link_url($ID);
531
+		if (! $checkout_url) {
532
+			EE_Error::add_error(
533
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534
+				__FILE__,
535
+				__FUNCTION__,
536
+				__LINE__
537
+			);
538
+		}
539
+		// set no cache headers and constants
540
+		EE_System::do_not_cache();
541
+		$html = '<form method="POST" ';
542
+		$html .= 'action="' . $checkout_url . '" ';
543
+		$html .= 'name="ticket-selector-form-' . $ID . '"';
544
+		$html .= $this->iframe ? ' target="_blank"' : '';
545
+		$html .= '>';
546
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
547
+		$html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
548
+		return $html;
549
+	}
550
+
551
+
552
+	/**
553
+	 * displaySubmitButton
554
+	 *
555
+	 * @param  string $external_url
556
+	 * @return string
557
+	 * @throws EE_Error
558
+	 */
559
+	public function displaySubmitButton($external_url = '')
560
+	{
561
+		$html = '';
562
+		if ($this->display_full_ui()) {
563
+			// standard TS displayed with submit button, ie: "Register Now"
564
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
565
+				$html .= $this->displayRegisterNowButton();
566
+				$html .= empty($external_url)
567
+					? $this->ticketSelectorEndDiv()
568
+					: $this->clearTicketSelector();
569
+				$html .= '<br/>' . $this->formClose();
570
+			} elseif ($this->getMaxAttendees() === 1) {
571
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572
+				if ($this->event->is_sold_out()) {
573
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
574
+					$html .= apply_filters(
575
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
576
+						sprintf(
577
+							__(
578
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
579
+								'event_espresso'
580
+							),
581
+							'<p class="no-ticket-selector-msg clear-float">',
582
+							$this->event->name(),
583
+							'</p>',
584
+							'<br />'
585
+						),
586
+						$this->event
587
+					);
588
+					if (apply_filters(
589
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
590
+						false,
591
+						$this->event
592
+					)) {
593
+						$html .= $this->displayRegisterNowButton();
594
+					}
595
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
596
+					$html .= $this->ticketSelectorEndDiv();
597
+				} elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
598
+						  && ! is_single()
599
+				) {
600
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
601
+					// but no tickets are available, so display event's "View Details" button.
602
+					// it is being viewed via somewhere other than a single post
603
+					$html .= $this->displayViewDetailsButton(true);
604
+				} else {
605
+					$html .= $this->ticketSelectorEndDiv();
606
+				}
607
+			} elseif (is_archive()) {
608
+				// event list, no tickets available so display event's "View Details" button
609
+				$html .= $this->ticketSelectorEndDiv();
610
+				$html .= $this->displayViewDetailsButton();
611
+			} else {
612
+				if (apply_filters(
613
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
614
+					false,
615
+					$this->event
616
+				)) {
617
+					$html .= $this->displayRegisterNowButton();
618
+				}
619
+				// no submit or view details button, and no additional content
620
+				$html .= $this->ticketSelectorEndDiv();
621
+			}
622
+			if (! $this->iframe && ! is_archive()) {
623
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624
+			}
625
+		}
626
+		return apply_filters(
627
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
628
+			$html,
629
+			$this->event,
630
+			$this
631
+		);
632
+	}
633
+
634
+
635
+	/**
636
+	 * @return string
637
+	 * @throws EE_Error
638
+	 */
639
+	public function displayRegisterNowButton()
640
+	{
641
+		$btn_text = apply_filters(
642
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
643
+			__('Register Now', 'event_espresso'),
644
+			$this->event
645
+		);
646
+		$external_url = (string) $this->event->external_url()
647
+			&& $this->event->external_url() !== get_the_permalink()
648
+			? $this->event->external_url()
649
+			: '';
650
+		$html = EEH_HTML::div(
651
+			'',
652
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
653
+			'ticket-selector-submit-btn-wrap'
654
+		);
655
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
656
+		$html .= ' class="ticket-selector-submit-btn ';
657
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
+		$html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
660
+		$html .= apply_filters(
661
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662
+			'',
663
+			$this->event,
664
+			$this->iframe
665
+		);
666
+		return $html;
667
+	}
668
+
669
+
670
+	/**
671
+	 * displayViewDetailsButton
672
+	 *
673
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
674
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
675
+	 *                    either because they are sold out, expired, or not yet on sale.
676
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
677
+	 * @return string
678
+	 * @throws EE_Error
679
+	 */
680
+	public function displayViewDetailsButton($DWMTS = false)
681
+	{
682
+		if (! $this->event->get_permalink()) {
683
+			EE_Error::add_error(
684
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685
+				__FILE__,
686
+				__FUNCTION__,
687
+				__LINE__
688
+			);
689
+		}
690
+		$view_details_btn = '<form method="GET" action="';
691
+		$view_details_btn .= apply_filters(
692
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
693
+			$this->event->get_permalink(),
694
+			$this->event
695
+		);
696
+		$view_details_btn .= '"';
697
+		// open link in new window ?
698
+		$view_details_btn .= apply_filters(
699
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
700
+			$this->isIframe(),
701
+			$this
702
+		)
703
+			? ' target="_blank"'
704
+			: '';
705
+		$view_details_btn .= '>';
706
+		$btn_text = apply_filters(
707
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
708
+			esc_html__('View Details', 'event_espresso'),
709
+			$this->event
710
+		);
711
+		$view_details_btn .= '<input id="ticket-selector-submit-'
712
+							 . $this->event->ID()
713
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
714
+							 . $btn_text
715
+							 . '" />';
716
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
717
+		if ($DWMTS) {
718
+			$view_details_btn .= $this->formClose();
719
+			$view_details_btn .= $this->ticketSelectorEndDiv();
720
+			$view_details_btn .= '<br/>';
721
+		} else {
722
+			$view_details_btn .= $this->clearTicketSelector();
723
+			$view_details_btn .= '<br/>';
724
+			$view_details_btn .= $this->formClose();
725
+		}
726
+		return $view_details_btn;
727
+	}
728
+
729
+
730
+	/**
731
+	 * @return string
732
+	 */
733
+	public function ticketSelectorEndDiv()
734
+	{
735
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
736
+	}
737
+
738
+
739
+	/**
740
+	 * @return string
741
+	 */
742
+	public function clearTicketSelector()
743
+	{
744
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
745
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
746
+	}
747
+
748
+
749
+	/**
750
+	 * @access        public
751
+	 * @return        string
752
+	 */
753
+	public function formClose()
754
+	{
755
+		return '</form>';
756
+	}
757 757
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -37,128 +37,128 @@
 block discarded – undo
37 37
  * @since           4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
             <div class="error">
49 49
                 <p>
50 50
                     <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
                 </p>
56 56
             </div>
57 57
             <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
             <div class="error">
74 74
                 <p>
75 75
                     <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
-                    );
86
-                    ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
+					);
86
+					?>
87 87
                 </p>
88 88
             </div>
89 89
             <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.7.rc.024');
105
-        }
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.7.rc.024');
105
+		}
106 106
 
107
-        /**
108
-         * espresso_plugin_activation
109
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
110
-         */
111
-        function espresso_plugin_activation()
112
-        {
113
-            update_option('ee_espresso_activation', true);
107
+		/**
108
+		 * espresso_plugin_activation
109
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
110
+		 */
111
+		function espresso_plugin_activation()
112
+		{
113
+			update_option('ee_espresso_activation', true);
114 114
 
115
-            // Run WP GraphQL activation callback
116
-            if (PHP_VERSION_ID < 70100) {
117
-                return;
118
-            }
119
-            if (! class_exists('WPGraphQL')) {
120
-                require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
121
-            }
122
-            graphql_init()->activate();
123
-        }
115
+			// Run WP GraphQL activation callback
116
+			if (PHP_VERSION_ID < 70100) {
117
+				return;
118
+			}
119
+			if (! class_exists('WPGraphQL')) {
120
+				require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
121
+			}
122
+			graphql_init()->activate();
123
+		}
124 124
 
125
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
125
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
126 126
 
127
-        /**
128
-         * espresso_plugin_deactivation
129
-         */
130
-        function espresso_plugin_deactivation()
131
-        {
132
-            // Run WP GraphQL deactivation callback
133
-            if (PHP_VERSION_ID < 70100) {
134
-                return;
135
-            }
136
-            if (! class_exists('WPGraphQL')) {
137
-                require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
138
-            }
139
-            graphql_init()->deactivate();
140
-        }
141
-        register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
127
+		/**
128
+		 * espresso_plugin_deactivation
129
+		 */
130
+		function espresso_plugin_deactivation()
131
+		{
132
+			// Run WP GraphQL deactivation callback
133
+			if (PHP_VERSION_ID < 70100) {
134
+				return;
135
+			}
136
+			if (! class_exists('WPGraphQL')) {
137
+				require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
138
+			}
139
+			graphql_init()->deactivate();
140
+		}
141
+		register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
142 142
 
143
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
144
-        bootstrap_espresso();
145
-    }
143
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
144
+		bootstrap_espresso();
145
+	}
146 146
 }
147 147
 if (! function_exists('espresso_deactivate_plugin')) {
148
-    /**
149
-     *    deactivate_plugin
150
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
151
-     *
152
-     * @access public
153
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
154
-     * @return    void
155
-     */
156
-    function espresso_deactivate_plugin($plugin_basename = '')
157
-    {
158
-        if (! function_exists('deactivate_plugins')) {
159
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
160
-        }
161
-        unset($_GET['activate'], $_REQUEST['activate']);
162
-        deactivate_plugins($plugin_basename);
163
-    }
148
+	/**
149
+	 *    deactivate_plugin
150
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
151
+	 *
152
+	 * @access public
153
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
154
+	 * @return    void
155
+	 */
156
+	function espresso_deactivate_plugin($plugin_basename = '')
157
+	{
158
+		if (! function_exists('deactivate_plugins')) {
159
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
160
+		}
161
+		unset($_GET['activate'], $_REQUEST['activate']);
162
+		deactivate_plugins($plugin_basename);
163
+	}
164 164
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -31,266 +31,266 @@
 block discarded – undo
31 31
 class CoreAssetManager extends AssetManager
32 32
 {
33 33
 
34
-    // WordPress core / Third party JS asset handles
35
-    const JS_HANDLE_JQUERY = 'jquery';
36
-
37
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
38
-
39
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
40
-
41
-    const JS_HANDLE_JS_CORE = 'eejs-core';
42
-
43
-    const JS_HANDLE_CORE = 'espresso_core';
44
-
45
-    const JS_HANDLE_I18N = 'eei18n';
46
-
47
-    const JS_HANDLE_VENDOR = 'eventespresso-vendor';
48
-
49
-    // EE CSS assets handles
50
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
51
-
52
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
53
-
54
-    /**
55
-     * @var EE_Currency_Config $currency_config
56
-     */
57
-    protected $currency_config;
58
-
59
-    /**
60
-     * @var EE_Template_Config $template_config
61
-     */
62
-    protected $template_config;
63
-
64
-
65
-    /**
66
-     * CoreAssetRegister constructor.
67
-     *
68
-     * @param AssetCollection    $assets
69
-     * @param EE_Currency_Config $currency_config
70
-     * @param EE_Template_Config $template_config
71
-     * @param DomainInterface    $domain
72
-     * @param Registry           $registry
73
-     */
74
-    public function __construct(
75
-        AssetCollection $assets,
76
-        EE_Currency_Config $currency_config,
77
-        EE_Template_Config $template_config,
78
-        DomainInterface $domain,
79
-        Registry $registry
80
-    ) {
81
-        $this->currency_config = $currency_config;
82
-        $this->template_config = $template_config;
83
-        parent::__construct($domain, $assets, $registry);
84
-    }
85
-
86
-
87
-    /**
88
-     * @since 4.9.62.p
89
-     * @throws DomainException
90
-     * @throws DuplicateCollectionIdentifierException
91
-     * @throws InvalidArgumentException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidEntityException
94
-     * @throws InvalidInterfaceException
95
-     */
96
-    public function addAssets()
97
-    {
98
-        $this->addJavascriptFiles();
99
-        $this->addStylesheetFiles();
100
-    }
101
-
102
-
103
-    /**
104
-     * @since 4.9.62.p
105
-     * @throws DomainException
106
-     * @throws DuplicateCollectionIdentifierException
107
-     * @throws InvalidArgumentException
108
-     * @throws InvalidDataTypeException
109
-     * @throws InvalidEntityException
110
-     * @throws InvalidInterfaceException
111
-     */
112
-    public function addJavascriptFiles()
113
-    {
114
-        $this->loadCoreJs();
115
-        $this->loadJqueryValidate();
116
-    }
117
-
118
-
119
-    /**
120
-     * @throws DuplicateCollectionIdentifierException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidEntityException
123
-     * @throws DomainException
124
-     * @since 4.9.62.p
125
-     */
126
-    public function addStylesheetFiles()
127
-    {
128
-        $this->loadCoreCss();
129
-    }
130
-
131
-
132
-    /**
133
-     * core default javascript
134
-     *
135
-     * @since 4.9.62.p
136
-     * @throws DomainException
137
-     * @throws DuplicateCollectionIdentifierException
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidEntityException
141
-     * @throws InvalidInterfaceException
142
-     */
143
-    private function loadCoreJs()
144
-    {
145
-        $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR);
146
-        $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData();
147
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
148
-        $this->registry->addData(
149
-            'paths',
150
-            array(
151
-                'base_rest_route' => rest_url(),
152
-                'rest_route' => rest_url('ee/v4.8.36/'),
153
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
154
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
155
-                'site_url' => site_url('/'),
156
-                'admin_url' => admin_url('/'),
157
-            )
158
-        );
159
-        // Event Espresso brand name
160
-        $this->registry->addData('brandName', Domain::brandName());
161
-        /** site formatting values **/
162
-        $this->registry->addData(
163
-            'site_formats',
164
-            array(
165
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
166
-            )
167
-        );
168
-        /** currency data **/
169
-        $this->registry->addData(
170
-            'currency_config',
171
-            $this->getCurrencySettings()
172
-        );
173
-        /** site timezone */
174
-        $this->registry->addData(
175
-            'default_timezone',
176
-            array(
177
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
178
-                'string' => get_option('timezone_string'),
179
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
180
-            )
181
-        );
182
-        /** site locale (user locale if user logged in) */
183
-        $this->registry->addData(
184
-            'locale',
185
-            array(
186
-                'user' => get_user_locale(),
187
-                'site' => get_locale()
188
-            )
189
-        );
190
-
191
-        $this->addJavascript(
192
-            CoreAssetManager::JS_HANDLE_CORE,
193
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
194
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
195
-        )
196
-        ->setInlineDataCallback(
197
-            static function () {
198
-                wp_localize_script(
199
-                    CoreAssetManager::JS_HANDLE_CORE,
200
-                    CoreAssetManager::JS_HANDLE_I18N,
201
-                    EE_Registry::$i18n_js_strings
202
-                );
203
-            }
204
-        );
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * Returns configuration data for the js Currency VO.
211
-     * @since 4.9.71.p
212
-     * @return array
213
-     */
214
-    private function getCurrencySettings()
215
-    {
216
-        return array(
217
-            'code' => $this->currency_config->code,
218
-            'singularLabel' => $this->currency_config->name,
219
-            'pluralLabel' => $this->currency_config->plural,
220
-            'sign' => $this->currency_config->sign,
221
-            'signB4' => $this->currency_config->sign_b4,
222
-            'decimalPlaces' => $this->currency_config->dec_plc,
223
-            'decimalMark' => $this->currency_config->dec_mrk,
224
-            'thousandsSeparator' => $this->currency_config->thsnds,
225
-        );
226
-    }
227
-
228
-
229
-    /**
230
-     * @throws DuplicateCollectionIdentifierException
231
-     * @throws InvalidDataTypeException
232
-     * @throws InvalidEntityException
233
-     * @throws DomainException
234
-     * @since 4.9.62.p
235
-     */
236
-    private function loadCoreCss()
237
-    {
238
-        if ($this->template_config->enable_default_style && ! is_admin()) {
239
-            $this->addStylesheet(
240
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
241
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css')
242
-                    ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css'
243
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
244
-                array('dashicons')
245
-            );
246
-            //Load custom style sheet if available
247
-            if ($this->template_config->custom_style_sheet !== null) {
248
-                $this->addStylesheet(
249
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
250
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
251
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
252
-                );
253
-            }
254
-        }
255
-    }
256
-
257
-
258
-    /**
259
-     * jQuery Validate for form validation
260
-     *
261
-     * @since 4.9.62.p
262
-     * @throws DomainException
263
-     * @throws DuplicateCollectionIdentifierException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidEntityException
266
-     */
267
-    private function loadJqueryValidate()
268
-    {
269
-        $this->addJavascript(
270
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
271
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
272
-            array(CoreAssetManager::JS_HANDLE_JQUERY),
273
-            true,
274
-            '1.15.0'
275
-        );
276
-
277
-        $this->addJavascript(
278
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
279
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
280
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
281
-            true,
282
-            '1.15.0'
283
-        );
284
-    }
285
-
286
-
287
-    /**
288
-     * @param JavascriptAsset $script
289
-     * @deprecated $VID:$
290
-     */
291
-    public function loadQtipJs(JavascriptAsset $script)
292
-    {
293
-        // replacement:
294
-        // \EventEspresso\core\domain\services\assets\EspressoAdminAssetManager::loadQtipJs
295
-    }
34
+	// WordPress core / Third party JS asset handles
35
+	const JS_HANDLE_JQUERY = 'jquery';
36
+
37
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
38
+
39
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
40
+
41
+	const JS_HANDLE_JS_CORE = 'eejs-core';
42
+
43
+	const JS_HANDLE_CORE = 'espresso_core';
44
+
45
+	const JS_HANDLE_I18N = 'eei18n';
46
+
47
+	const JS_HANDLE_VENDOR = 'eventespresso-vendor';
48
+
49
+	// EE CSS assets handles
50
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
51
+
52
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
53
+
54
+	/**
55
+	 * @var EE_Currency_Config $currency_config
56
+	 */
57
+	protected $currency_config;
58
+
59
+	/**
60
+	 * @var EE_Template_Config $template_config
61
+	 */
62
+	protected $template_config;
63
+
64
+
65
+	/**
66
+	 * CoreAssetRegister constructor.
67
+	 *
68
+	 * @param AssetCollection    $assets
69
+	 * @param EE_Currency_Config $currency_config
70
+	 * @param EE_Template_Config $template_config
71
+	 * @param DomainInterface    $domain
72
+	 * @param Registry           $registry
73
+	 */
74
+	public function __construct(
75
+		AssetCollection $assets,
76
+		EE_Currency_Config $currency_config,
77
+		EE_Template_Config $template_config,
78
+		DomainInterface $domain,
79
+		Registry $registry
80
+	) {
81
+		$this->currency_config = $currency_config;
82
+		$this->template_config = $template_config;
83
+		parent::__construct($domain, $assets, $registry);
84
+	}
85
+
86
+
87
+	/**
88
+	 * @since 4.9.62.p
89
+	 * @throws DomainException
90
+	 * @throws DuplicateCollectionIdentifierException
91
+	 * @throws InvalidArgumentException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidEntityException
94
+	 * @throws InvalidInterfaceException
95
+	 */
96
+	public function addAssets()
97
+	{
98
+		$this->addJavascriptFiles();
99
+		$this->addStylesheetFiles();
100
+	}
101
+
102
+
103
+	/**
104
+	 * @since 4.9.62.p
105
+	 * @throws DomainException
106
+	 * @throws DuplicateCollectionIdentifierException
107
+	 * @throws InvalidArgumentException
108
+	 * @throws InvalidDataTypeException
109
+	 * @throws InvalidEntityException
110
+	 * @throws InvalidInterfaceException
111
+	 */
112
+	public function addJavascriptFiles()
113
+	{
114
+		$this->loadCoreJs();
115
+		$this->loadJqueryValidate();
116
+	}
117
+
118
+
119
+	/**
120
+	 * @throws DuplicateCollectionIdentifierException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidEntityException
123
+	 * @throws DomainException
124
+	 * @since 4.9.62.p
125
+	 */
126
+	public function addStylesheetFiles()
127
+	{
128
+		$this->loadCoreCss();
129
+	}
130
+
131
+
132
+	/**
133
+	 * core default javascript
134
+	 *
135
+	 * @since 4.9.62.p
136
+	 * @throws DomainException
137
+	 * @throws DuplicateCollectionIdentifierException
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidEntityException
141
+	 * @throws InvalidInterfaceException
142
+	 */
143
+	private function loadCoreJs()
144
+	{
145
+		$this->addJs(CoreAssetManager::JS_HANDLE_VENDOR);
146
+		$this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData();
147
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
148
+		$this->registry->addData(
149
+			'paths',
150
+			array(
151
+				'base_rest_route' => rest_url(),
152
+				'rest_route' => rest_url('ee/v4.8.36/'),
153
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
154
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
155
+				'site_url' => site_url('/'),
156
+				'admin_url' => admin_url('/'),
157
+			)
158
+		);
159
+		// Event Espresso brand name
160
+		$this->registry->addData('brandName', Domain::brandName());
161
+		/** site formatting values **/
162
+		$this->registry->addData(
163
+			'site_formats',
164
+			array(
165
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
166
+			)
167
+		);
168
+		/** currency data **/
169
+		$this->registry->addData(
170
+			'currency_config',
171
+			$this->getCurrencySettings()
172
+		);
173
+		/** site timezone */
174
+		$this->registry->addData(
175
+			'default_timezone',
176
+			array(
177
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
178
+				'string' => get_option('timezone_string'),
179
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
180
+			)
181
+		);
182
+		/** site locale (user locale if user logged in) */
183
+		$this->registry->addData(
184
+			'locale',
185
+			array(
186
+				'user' => get_user_locale(),
187
+				'site' => get_locale()
188
+			)
189
+		);
190
+
191
+		$this->addJavascript(
192
+			CoreAssetManager::JS_HANDLE_CORE,
193
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
194
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
195
+		)
196
+		->setInlineDataCallback(
197
+			static function () {
198
+				wp_localize_script(
199
+					CoreAssetManager::JS_HANDLE_CORE,
200
+					CoreAssetManager::JS_HANDLE_I18N,
201
+					EE_Registry::$i18n_js_strings
202
+				);
203
+			}
204
+		);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * Returns configuration data for the js Currency VO.
211
+	 * @since 4.9.71.p
212
+	 * @return array
213
+	 */
214
+	private function getCurrencySettings()
215
+	{
216
+		return array(
217
+			'code' => $this->currency_config->code,
218
+			'singularLabel' => $this->currency_config->name,
219
+			'pluralLabel' => $this->currency_config->plural,
220
+			'sign' => $this->currency_config->sign,
221
+			'signB4' => $this->currency_config->sign_b4,
222
+			'decimalPlaces' => $this->currency_config->dec_plc,
223
+			'decimalMark' => $this->currency_config->dec_mrk,
224
+			'thousandsSeparator' => $this->currency_config->thsnds,
225
+		);
226
+	}
227
+
228
+
229
+	/**
230
+	 * @throws DuplicateCollectionIdentifierException
231
+	 * @throws InvalidDataTypeException
232
+	 * @throws InvalidEntityException
233
+	 * @throws DomainException
234
+	 * @since 4.9.62.p
235
+	 */
236
+	private function loadCoreCss()
237
+	{
238
+		if ($this->template_config->enable_default_style && ! is_admin()) {
239
+			$this->addStylesheet(
240
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
241
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css')
242
+					? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css'
243
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
244
+				array('dashicons')
245
+			);
246
+			//Load custom style sheet if available
247
+			if ($this->template_config->custom_style_sheet !== null) {
248
+				$this->addStylesheet(
249
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
250
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
251
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
252
+				);
253
+			}
254
+		}
255
+	}
256
+
257
+
258
+	/**
259
+	 * jQuery Validate for form validation
260
+	 *
261
+	 * @since 4.9.62.p
262
+	 * @throws DomainException
263
+	 * @throws DuplicateCollectionIdentifierException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidEntityException
266
+	 */
267
+	private function loadJqueryValidate()
268
+	{
269
+		$this->addJavascript(
270
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
271
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
272
+			array(CoreAssetManager::JS_HANDLE_JQUERY),
273
+			true,
274
+			'1.15.0'
275
+		);
276
+
277
+		$this->addJavascript(
278
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
279
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
280
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
281
+			true,
282
+			'1.15.0'
283
+		);
284
+	}
285
+
286
+
287
+	/**
288
+	 * @param JavascriptAsset $script
289
+	 * @deprecated $VID:$
290
+	 */
291
+	public function loadQtipJs(JavascriptAsset $script)
292
+	{
293
+		// replacement:
294
+		// \EventEspresso\core\domain\services\assets\EspressoAdminAssetManager::loadQtipJs
295
+	}
296 296
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 
191 191
         $this->addJavascript(
192 192
             CoreAssetManager::JS_HANDLE_CORE,
193
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
193
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
194 194
             array(CoreAssetManager::JS_HANDLE_JQUERY)
195 195
         )
196 196
         ->setInlineDataCallback(
197
-            static function () {
197
+            static function() {
198 198
                 wp_localize_script(
199 199
                     CoreAssetManager::JS_HANDLE_CORE,
200 200
                     CoreAssetManager::JS_HANDLE_I18N,
@@ -238,16 +238,16 @@  discard block
 block discarded – undo
238 238
         if ($this->template_config->enable_default_style && ! is_admin()) {
239 239
             $this->addStylesheet(
240 240
                 CoreAssetManager::CSS_HANDLE_DEFAULT,
241
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css')
241
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css')
242 242
                     ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css'
243
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
243
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
244 244
                 array('dashicons')
245 245
             );
246 246
             //Load custom style sheet if available
247 247
             if ($this->template_config->custom_style_sheet !== null) {
248 248
                 $this->addStylesheet(
249 249
                     CoreAssetManager::CSS_HANDLE_CUSTOM,
250
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
250
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
251 251
                     array(CoreAssetManager::CSS_HANDLE_DEFAULT)
252 252
                 );
253 253
             }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     {
269 269
         $this->addJavascript(
270 270
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
271
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
271
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
272 272
             array(CoreAssetManager::JS_HANDLE_JQUERY),
273 273
             true,
274 274
             '1.15.0'
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
         $this->addJavascript(
278 278
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
279
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
279
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
280 280
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
281 281
             true,
282 282
             '1.15.0'
Please login to merge, or discard this patch.