Completed
Branch BUG/11302/correct-error-messag... (35e058)
by
unknown
31:52 queued 18:08
created
admin_pages/events/Events_Admin_List_Table.class.php 1 patch
Indentation   +526 added lines, -526 removed lines patch added patch discarded remove patch
@@ -18,530 +18,530 @@
 block discarded – undo
18 18
 class Events_Admin_List_Table extends EE_Admin_List_Table
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Datetime
23
-     */
24
-    private $_dtt;
25
-
26
-
27
-
28
-    /**
29
-     * Initial setup of data properties for the list table.
30
-     */
31
-    protected function _setup_data()
32
-    {
33
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
34
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * Set up of additional properties for the list table.
41
-     */
42
-    protected function _set_properties()
43
-    {
44
-        $this->_wp_list_args = array(
45
-            'singular' => esc_html__('event', 'event_espresso'),
46
-            'plural'   => esc_html__('events', 'event_espresso'),
47
-            'ajax'     => true, //for now
48
-            'screen'   => $this->_admin_page->get_current_screen()->id,
49
-        );
50
-        $this->_columns = array(
51
-            'cb'              => '<input type="checkbox" />',
52
-            'id'              => esc_html__('ID', 'event_espresso'),
53
-            'name'            => esc_html__('Name', 'event_espresso'),
54
-            'author'          => esc_html__('Author', 'event_espresso'),
55
-            'venue'           => esc_html__('Venue', 'event_espresso'),
56
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
57
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
58
-            'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
59
-                                 . '<span class="screen-reader-text">'
60
-                                 . esc_html__('Approved Registrations', 'event_espresso')
61
-                                 . '</span>'
62
-                                 . '</span>',
63
-            //'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
64
-            'actions'         => esc_html__('Actions', 'event_espresso'),
65
-        );
66
-        $this->_sortable_columns = array(
67
-            'id'              => array('EVT_ID' => true),
68
-            'name'            => array('EVT_name' => false),
69
-            'author'          => array('EVT_wp_user' => false),
70
-            'venue'           => array('Venue.VNU_name' => false),
71
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
72
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
73
-        );
74
-        $this->_primary_column = 'id';
75
-        $this->_hidden_columns = array('author');
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * @return array
82
-     */
83
-    protected function _get_table_filters()
84
-    {
85
-        return array(); //no filters with decaf
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * Setup of views properties.
92
-     *
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidArgumentException
96
-     */
97
-    protected function _add_view_counts()
98
-    {
99
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
100
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
101
-        if (EE_Registry::instance()->CAP->current_user_can(
102
-            'ee_delete_events',
103
-            'espresso_events_trash_events'
104
-        )) {
105
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
106
-        }
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * @param EE_Event $item
113
-     * @return string
114
-     * @throws EE_Error
115
-     */
116
-    protected function _get_row_class($item)
117
-    {
118
-        $class = parent::_get_row_class($item);
119
-        //add status class
120
-        $class .= $item instanceof EE_Event
121
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
122
-            : '';
123
-        if ($this->_has_checkbox_column) {
124
-            $class .= ' has-checkbox-column';
125
-        }
126
-        return $class;
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * @param EE_Event $item
133
-     * @return string
134
-     * @throws EE_Error
135
-     */
136
-    public function column_status(EE_Event $item)
137
-    {
138
-        return '<span class="ee-status-strip ee-status-strip-td event-status-'
139
-               . $item->get_active_status()
140
-               . '"></span>';
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @param  EE_Event $item
147
-     * @return string
148
-     * @throws EE_Error
149
-     */
150
-    public function column_cb($item)
151
-    {
152
-        if (! $item instanceof EE_Event) {
153
-            return '';
154
-        }
155
-        $this->_dtt = $item->primary_datetime(); //set this for use in other columns
156
-        //does event have any attached registrations?
157
-        $regs = $item->count_related('Registration');
158
-        return $regs > 0 && $this->_view === 'trash'
159
-            ? '<span class="ee-lock-icon"></span>'
160
-            : sprintf(
161
-                '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
162
-                $item->ID()
163
-            );
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * @param EE_Event $item
170
-     * @return mixed|string
171
-     * @throws EE_Error
172
-     */
173
-    public function column_id(EE_Event $item)
174
-    {
175
-        $content = $item->ID();
176
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
177
-        return $content;
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * @param EE_Event $item
184
-     * @return string
185
-     * @throws EE_Error
186
-     * @throws InvalidArgumentException
187
-     * @throws InvalidDataTypeException
188
-     * @throws InvalidInterfaceException
189
-     */
190
-    public function column_name(EE_Event $item)
191
-    {
192
-        $edit_query_args = array(
193
-            'action' => 'edit',
194
-            'post'   => $item->ID(),
195
-        );
196
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
197
-        $actions = $this->_column_name_action_setup($item);
198
-        $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
199
-        $content = '<strong><a class="row-title" href="'
200
-                   . $edit_link . '">'
201
-                   . $item->name()
202
-                   . '</a></strong>'
203
-                   . $status;
204
-        $content .= '<br><span class="ee-status-text-small">'
205
-                    . EEH_Template::pretty_status(
206
-                $item->get_active_status(),
207
-                false,
208
-                'sentence'
209
-            )
210
-                    . '</span>';
211
-        $content .= $this->row_actions($actions);
212
-        return $content;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * Just a method for setting up the actions for the name column
219
-     *
220
-     * @param EE_Event $item
221
-     * @return array array of actions
222
-     * @throws EE_Error
223
-     * @throws InvalidArgumentException
224
-     * @throws InvalidDataTypeException
225
-     * @throws InvalidInterfaceException
226
-     */
227
-    protected function _column_name_action_setup(EE_Event $item)
228
-    {
229
-        //todo: remove when attendees is active
230
-        if (! defined('REG_ADMIN_URL')) {
231
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
232
-        }
233
-        $actions = array();
234
-        $restore_event_link = '';
235
-        $delete_event_link = '';
236
-        $trash_event_link = '';
237
-        if (EE_Registry::instance()->CAP->current_user_can(
238
-            'ee_edit_event',
239
-            'espresso_events_edit',
240
-            $item->ID()
241
-        )) {
242
-            $edit_query_args = array(
243
-                'action' => 'edit',
244
-                'post'   => $item->ID(),
245
-            );
246
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
247
-            $actions['edit'] = '<a href="' . $edit_link . '"'
248
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
249
-                               . esc_html__('Edit', 'event_espresso')
250
-                               . '</a>';
251
-        }
252
-        if (
253
-            EE_Registry::instance()->CAP->current_user_can(
254
-                'ee_read_registrations',
255
-                'espresso_registrations_view_registration'
256
-            )
257
-            && EE_Registry::instance()->CAP->current_user_can(
258
-                'ee_read_event',
259
-                'espresso_registrations_view_registration',
260
-                $item->ID()
261
-            )
262
-        ) {
263
-            $attendees_query_args = array(
264
-                'action'   => 'default',
265
-                'event_id' => $item->ID(),
266
-            );
267
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
268
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
269
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
270
-                                    . esc_html__('Registrations', 'event_espresso')
271
-                                    . '</a>';
272
-        }
273
-        if (
274
-        EE_Registry::instance()->CAP->current_user_can(
275
-            'ee_delete_event',
276
-            'espresso_events_trash_event',
277
-            $item->ID()
278
-        )
279
-        ) {
280
-            $trash_event_query_args = array(
281
-                'action' => 'trash_event',
282
-                'EVT_ID' => $item->ID(),
283
-            );
284
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
285
-                $trash_event_query_args,
286
-                EVENTS_ADMIN_URL
287
-            );
288
-        }
289
-        if (
290
-        EE_Registry::instance()->CAP->current_user_can(
291
-            'ee_delete_event',
292
-            'espresso_events_restore_event',
293
-            $item->ID()
294
-        )
295
-        ) {
296
-            $restore_event_query_args = array(
297
-                'action' => 'restore_event',
298
-                'EVT_ID' => $item->ID(),
299
-            );
300
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
301
-                $restore_event_query_args,
302
-                EVENTS_ADMIN_URL
303
-            );
304
-        }
305
-        if (
306
-        EE_Registry::instance()->CAP->current_user_can(
307
-            'ee_delete_event',
308
-            'espresso_events_delete_event',
309
-            $item->ID()
310
-        )
311
-        ) {
312
-            $delete_event_query_args = array(
313
-                'action' => 'delete_event',
314
-                'EVT_ID' => $item->ID(),
315
-            );
316
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
317
-                $delete_event_query_args,
318
-                EVENTS_ADMIN_URL
319
-            );
320
-        }
321
-        $view_link = get_permalink($item->ID());
322
-        $actions['view'] = '<a href="' . $view_link . '"'
323
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
324
-                           . esc_html__('View', 'event_espresso')
325
-                           . '</a>';
326
-        if ($item->get('status') === 'trash') {
327
-            if (EE_Registry::instance()->CAP->current_user_can(
328
-                'ee_delete_event',
329
-                'espresso_events_restore_event',
330
-                $item->ID()
331
-            )) {
332
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
333
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
334
-                                                 . '">'
335
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
336
-                                                 . '</a>';
337
-            }
338
-            if (
339
-                $item->count_related('Registration') === 0
340
-                && EE_Registry::instance()->CAP->current_user_can(
341
-                    'ee_delete_event',
342
-                    'espresso_events_delete_event',
343
-                    $item->ID()
344
-                )
345
-            ) {
346
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
347
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
348
-                                     . esc_html__('Delete Permanently', 'event_espresso')
349
-                                     . '</a>';
350
-            }
351
-        } else {
352
-            if (
353
-                EE_Registry::instance()->CAP->current_user_can(
354
-                    'ee_delete_event',
355
-                    'espresso_events_trash_event',
356
-                    $item->ID()
357
-                )
358
-            ) {
359
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
360
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
361
-                                            . esc_html__('Trash', 'event_espresso')
362
-                                            . '</a>';
363
-            }
364
-        }
365
-        return $actions;
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * @param EE_Event $item
372
-     * @return string
373
-     * @throws EE_Error
374
-     */
375
-    public function column_author(EE_Event $item)
376
-    {
377
-        //user author info
378
-        $event_author = get_userdata($item->wp_user());
379
-        $gravatar = get_avatar($item->wp_user(), '15');
380
-        //filter link
381
-        $query_args = array(
382
-            'action'      => 'default',
383
-            'EVT_wp_user' => $item->wp_user(),
384
-        );
385
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
386
-        return $gravatar . '  <a href="' . $filter_url . '"'
387
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
388
-               . $event_author->display_name
389
-               . '</a>';
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * @param EE_Event $item
396
-     * @return string
397
-     * @throws EE_Error
398
-     */
399
-    public function column_venue(EE_Event $item)
400
-    {
401
-        $venue = $item->get_first_related('Venue');
402
-        return ! empty($venue)
403
-            ? $venue->name()
404
-            : '';
405
-    }
406
-
407
-
408
-    /**
409
-     * @param EE_Event $item
410
-     * @return string
411
-     * @throws EE_Error
412
-     */
413
-    public function column_start_date_time(EE_Event $item)
414
-    {
415
-        return $this->_dtt instanceof EE_Datetime
416
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
417
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
418
-    }
419
-
420
-
421
-    /**
422
-     * @param EE_Event $item
423
-     * @return string
424
-     * @throws EE_Error
425
-     */
426
-    public function column_reg_begins(EE_Event $item)
427
-    {
428
-        $reg_start = $item->get_ticket_with_earliest_start_time();
429
-        return $reg_start instanceof EE_Ticket
430
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
431
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     * @param EE_Event $item
438
-     * @return int|string
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws InvalidDataTypeException
442
-     * @throws InvalidInterfaceException
443
-     */
444
-    public function column_attendees(EE_Event $item)
445
-    {
446
-        $attendees_query_args = array(
447
-            'action'   => 'default',
448
-            'event_id' => $item->ID(),
449
-        );
450
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
451
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
452
-        return EE_Registry::instance()->CAP->current_user_can(
453
-            'ee_read_event',
454
-            'espresso_registrations_view_registration',
455
-            $item->ID()
456
-        )
457
-               && EE_Registry::instance()->CAP->current_user_can(
458
-            'ee_read_registrations',
459
-            'espresso_registrations_view_registration'
460
-        )
461
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
462
-            : $registered_attendees;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * @param EE_Event $item
469
-     * @return float
470
-     * @throws EE_Error
471
-     * @throws InvalidArgumentException
472
-     * @throws InvalidDataTypeException
473
-     * @throws InvalidInterfaceException
474
-     */
475
-    public function column_tkts_sold(EE_Event $item)
476
-    {
477
-        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
478
-    }
479
-
480
-
481
-
482
-    /**
483
-     * @param EE_Event $item
484
-     * @return string
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     */
490
-    public function column_actions(EE_Event $item)
491
-    {
492
-        //todo: remove when attendees is active
493
-        if (! defined('REG_ADMIN_URL')) {
494
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
495
-        }
496
-        $action_links = array();
497
-        $view_link = get_permalink($item->ID());
498
-        $action_links[] = '<a href="' . $view_link . '"'
499
-                         . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
500
-        $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
501
-        if (EE_Registry::instance()->CAP->current_user_can(
502
-            'ee_edit_event',
503
-            'espresso_events_edit',
504
-            $item->ID()
505
-        )) {
506
-            $edit_query_args = array(
507
-                'action' => 'edit',
508
-                'post'   => $item->ID(),
509
-            );
510
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
511
-            $action_links[] = '<a href="' . $edit_link . '"'
512
-                             . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
513
-                             . '<div class="ee-icon ee-icon-calendar-edit"></div>'
514
-                             . '</a>';
515
-        }
516
-        if (
517
-            EE_Registry::instance()->CAP->current_user_can(
518
-                'ee_read_registrations',
519
-                'espresso_registrations_view_registration'
520
-            ) && EE_Registry::instance()->CAP->current_user_can(
521
-                'ee_read_event',
522
-                'espresso_registrations_view_registration',
523
-                $item->ID()
524
-            )
525
-        ) {
526
-            $attendees_query_args = array(
527
-                'action'   => 'default',
528
-                'event_id' => $item->ID(),
529
-            );
530
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
531
-            $action_links[] = '<a href="' . $attendees_link . '"'
532
-                             . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
533
-                             . '<div class="dashicons dashicons-groups"></div>'
534
-                             . '</a>';
535
-        }
536
-        $action_links = apply_filters(
537
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
538
-            $action_links,
539
-            $item
540
-        );
541
-        return $this->_action_string(
542
-            implode("\n\t", $action_links),
543
-            $item,
544
-            'div'
545
-        );
546
-    }
21
+	/**
22
+	 * @var EE_Datetime
23
+	 */
24
+	private $_dtt;
25
+
26
+
27
+
28
+	/**
29
+	 * Initial setup of data properties for the list table.
30
+	 */
31
+	protected function _setup_data()
32
+	{
33
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
34
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * Set up of additional properties for the list table.
41
+	 */
42
+	protected function _set_properties()
43
+	{
44
+		$this->_wp_list_args = array(
45
+			'singular' => esc_html__('event', 'event_espresso'),
46
+			'plural'   => esc_html__('events', 'event_espresso'),
47
+			'ajax'     => true, //for now
48
+			'screen'   => $this->_admin_page->get_current_screen()->id,
49
+		);
50
+		$this->_columns = array(
51
+			'cb'              => '<input type="checkbox" />',
52
+			'id'              => esc_html__('ID', 'event_espresso'),
53
+			'name'            => esc_html__('Name', 'event_espresso'),
54
+			'author'          => esc_html__('Author', 'event_espresso'),
55
+			'venue'           => esc_html__('Venue', 'event_espresso'),
56
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
57
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
58
+			'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
59
+								 . '<span class="screen-reader-text">'
60
+								 . esc_html__('Approved Registrations', 'event_espresso')
61
+								 . '</span>'
62
+								 . '</span>',
63
+			//'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
64
+			'actions'         => esc_html__('Actions', 'event_espresso'),
65
+		);
66
+		$this->_sortable_columns = array(
67
+			'id'              => array('EVT_ID' => true),
68
+			'name'            => array('EVT_name' => false),
69
+			'author'          => array('EVT_wp_user' => false),
70
+			'venue'           => array('Venue.VNU_name' => false),
71
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
72
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
73
+		);
74
+		$this->_primary_column = 'id';
75
+		$this->_hidden_columns = array('author');
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * @return array
82
+	 */
83
+	protected function _get_table_filters()
84
+	{
85
+		return array(); //no filters with decaf
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * Setup of views properties.
92
+	 *
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidArgumentException
96
+	 */
97
+	protected function _add_view_counts()
98
+	{
99
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
100
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
101
+		if (EE_Registry::instance()->CAP->current_user_can(
102
+			'ee_delete_events',
103
+			'espresso_events_trash_events'
104
+		)) {
105
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
106
+		}
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * @param EE_Event $item
113
+	 * @return string
114
+	 * @throws EE_Error
115
+	 */
116
+	protected function _get_row_class($item)
117
+	{
118
+		$class = parent::_get_row_class($item);
119
+		//add status class
120
+		$class .= $item instanceof EE_Event
121
+			? ' ee-status-strip event-status-' . $item->get_active_status()
122
+			: '';
123
+		if ($this->_has_checkbox_column) {
124
+			$class .= ' has-checkbox-column';
125
+		}
126
+		return $class;
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * @param EE_Event $item
133
+	 * @return string
134
+	 * @throws EE_Error
135
+	 */
136
+	public function column_status(EE_Event $item)
137
+	{
138
+		return '<span class="ee-status-strip ee-status-strip-td event-status-'
139
+			   . $item->get_active_status()
140
+			   . '"></span>';
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @param  EE_Event $item
147
+	 * @return string
148
+	 * @throws EE_Error
149
+	 */
150
+	public function column_cb($item)
151
+	{
152
+		if (! $item instanceof EE_Event) {
153
+			return '';
154
+		}
155
+		$this->_dtt = $item->primary_datetime(); //set this for use in other columns
156
+		//does event have any attached registrations?
157
+		$regs = $item->count_related('Registration');
158
+		return $regs > 0 && $this->_view === 'trash'
159
+			? '<span class="ee-lock-icon"></span>'
160
+			: sprintf(
161
+				'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
162
+				$item->ID()
163
+			);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * @param EE_Event $item
170
+	 * @return mixed|string
171
+	 * @throws EE_Error
172
+	 */
173
+	public function column_id(EE_Event $item)
174
+	{
175
+		$content = $item->ID();
176
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
177
+		return $content;
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * @param EE_Event $item
184
+	 * @return string
185
+	 * @throws EE_Error
186
+	 * @throws InvalidArgumentException
187
+	 * @throws InvalidDataTypeException
188
+	 * @throws InvalidInterfaceException
189
+	 */
190
+	public function column_name(EE_Event $item)
191
+	{
192
+		$edit_query_args = array(
193
+			'action' => 'edit',
194
+			'post'   => $item->ID(),
195
+		);
196
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
197
+		$actions = $this->_column_name_action_setup($item);
198
+		$status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
199
+		$content = '<strong><a class="row-title" href="'
200
+				   . $edit_link . '">'
201
+				   . $item->name()
202
+				   . '</a></strong>'
203
+				   . $status;
204
+		$content .= '<br><span class="ee-status-text-small">'
205
+					. EEH_Template::pretty_status(
206
+				$item->get_active_status(),
207
+				false,
208
+				'sentence'
209
+			)
210
+					. '</span>';
211
+		$content .= $this->row_actions($actions);
212
+		return $content;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * Just a method for setting up the actions for the name column
219
+	 *
220
+	 * @param EE_Event $item
221
+	 * @return array array of actions
222
+	 * @throws EE_Error
223
+	 * @throws InvalidArgumentException
224
+	 * @throws InvalidDataTypeException
225
+	 * @throws InvalidInterfaceException
226
+	 */
227
+	protected function _column_name_action_setup(EE_Event $item)
228
+	{
229
+		//todo: remove when attendees is active
230
+		if (! defined('REG_ADMIN_URL')) {
231
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
232
+		}
233
+		$actions = array();
234
+		$restore_event_link = '';
235
+		$delete_event_link = '';
236
+		$trash_event_link = '';
237
+		if (EE_Registry::instance()->CAP->current_user_can(
238
+			'ee_edit_event',
239
+			'espresso_events_edit',
240
+			$item->ID()
241
+		)) {
242
+			$edit_query_args = array(
243
+				'action' => 'edit',
244
+				'post'   => $item->ID(),
245
+			);
246
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
247
+			$actions['edit'] = '<a href="' . $edit_link . '"'
248
+							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
249
+							   . esc_html__('Edit', 'event_espresso')
250
+							   . '</a>';
251
+		}
252
+		if (
253
+			EE_Registry::instance()->CAP->current_user_can(
254
+				'ee_read_registrations',
255
+				'espresso_registrations_view_registration'
256
+			)
257
+			&& EE_Registry::instance()->CAP->current_user_can(
258
+				'ee_read_event',
259
+				'espresso_registrations_view_registration',
260
+				$item->ID()
261
+			)
262
+		) {
263
+			$attendees_query_args = array(
264
+				'action'   => 'default',
265
+				'event_id' => $item->ID(),
266
+			);
267
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
268
+			$actions['attendees'] = '<a href="' . $attendees_link . '"'
269
+									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
270
+									. esc_html__('Registrations', 'event_espresso')
271
+									. '</a>';
272
+		}
273
+		if (
274
+		EE_Registry::instance()->CAP->current_user_can(
275
+			'ee_delete_event',
276
+			'espresso_events_trash_event',
277
+			$item->ID()
278
+		)
279
+		) {
280
+			$trash_event_query_args = array(
281
+				'action' => 'trash_event',
282
+				'EVT_ID' => $item->ID(),
283
+			);
284
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
285
+				$trash_event_query_args,
286
+				EVENTS_ADMIN_URL
287
+			);
288
+		}
289
+		if (
290
+		EE_Registry::instance()->CAP->current_user_can(
291
+			'ee_delete_event',
292
+			'espresso_events_restore_event',
293
+			$item->ID()
294
+		)
295
+		) {
296
+			$restore_event_query_args = array(
297
+				'action' => 'restore_event',
298
+				'EVT_ID' => $item->ID(),
299
+			);
300
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
301
+				$restore_event_query_args,
302
+				EVENTS_ADMIN_URL
303
+			);
304
+		}
305
+		if (
306
+		EE_Registry::instance()->CAP->current_user_can(
307
+			'ee_delete_event',
308
+			'espresso_events_delete_event',
309
+			$item->ID()
310
+		)
311
+		) {
312
+			$delete_event_query_args = array(
313
+				'action' => 'delete_event',
314
+				'EVT_ID' => $item->ID(),
315
+			);
316
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
317
+				$delete_event_query_args,
318
+				EVENTS_ADMIN_URL
319
+			);
320
+		}
321
+		$view_link = get_permalink($item->ID());
322
+		$actions['view'] = '<a href="' . $view_link . '"'
323
+						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
324
+						   . esc_html__('View', 'event_espresso')
325
+						   . '</a>';
326
+		if ($item->get('status') === 'trash') {
327
+			if (EE_Registry::instance()->CAP->current_user_can(
328
+				'ee_delete_event',
329
+				'espresso_events_restore_event',
330
+				$item->ID()
331
+			)) {
332
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
333
+												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
334
+												 . '">'
335
+												 . esc_html__('Restore from Trash', 'event_espresso')
336
+												 . '</a>';
337
+			}
338
+			if (
339
+				$item->count_related('Registration') === 0
340
+				&& EE_Registry::instance()->CAP->current_user_can(
341
+					'ee_delete_event',
342
+					'espresso_events_delete_event',
343
+					$item->ID()
344
+				)
345
+			) {
346
+				$actions['delete'] = '<a href="' . $delete_event_link . '"'
347
+									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
348
+									 . esc_html__('Delete Permanently', 'event_espresso')
349
+									 . '</a>';
350
+			}
351
+		} else {
352
+			if (
353
+				EE_Registry::instance()->CAP->current_user_can(
354
+					'ee_delete_event',
355
+					'espresso_events_trash_event',
356
+					$item->ID()
357
+				)
358
+			) {
359
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '"'
360
+											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
361
+											. esc_html__('Trash', 'event_espresso')
362
+											. '</a>';
363
+			}
364
+		}
365
+		return $actions;
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * @param EE_Event $item
372
+	 * @return string
373
+	 * @throws EE_Error
374
+	 */
375
+	public function column_author(EE_Event $item)
376
+	{
377
+		//user author info
378
+		$event_author = get_userdata($item->wp_user());
379
+		$gravatar = get_avatar($item->wp_user(), '15');
380
+		//filter link
381
+		$query_args = array(
382
+			'action'      => 'default',
383
+			'EVT_wp_user' => $item->wp_user(),
384
+		);
385
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
386
+		return $gravatar . '  <a href="' . $filter_url . '"'
387
+			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
388
+			   . $event_author->display_name
389
+			   . '</a>';
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * @param EE_Event $item
396
+	 * @return string
397
+	 * @throws EE_Error
398
+	 */
399
+	public function column_venue(EE_Event $item)
400
+	{
401
+		$venue = $item->get_first_related('Venue');
402
+		return ! empty($venue)
403
+			? $venue->name()
404
+			: '';
405
+	}
406
+
407
+
408
+	/**
409
+	 * @param EE_Event $item
410
+	 * @return string
411
+	 * @throws EE_Error
412
+	 */
413
+	public function column_start_date_time(EE_Event $item)
414
+	{
415
+		return $this->_dtt instanceof EE_Datetime
416
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
417
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
418
+	}
419
+
420
+
421
+	/**
422
+	 * @param EE_Event $item
423
+	 * @return string
424
+	 * @throws EE_Error
425
+	 */
426
+	public function column_reg_begins(EE_Event $item)
427
+	{
428
+		$reg_start = $item->get_ticket_with_earliest_start_time();
429
+		return $reg_start instanceof EE_Ticket
430
+			? $reg_start->get_i18n_datetime('TKT_start_date')
431
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 * @param EE_Event $item
438
+	 * @return int|string
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws InvalidDataTypeException
442
+	 * @throws InvalidInterfaceException
443
+	 */
444
+	public function column_attendees(EE_Event $item)
445
+	{
446
+		$attendees_query_args = array(
447
+			'action'   => 'default',
448
+			'event_id' => $item->ID(),
449
+		);
450
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
451
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
452
+		return EE_Registry::instance()->CAP->current_user_can(
453
+			'ee_read_event',
454
+			'espresso_registrations_view_registration',
455
+			$item->ID()
456
+		)
457
+			   && EE_Registry::instance()->CAP->current_user_can(
458
+			'ee_read_registrations',
459
+			'espresso_registrations_view_registration'
460
+		)
461
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
462
+			: $registered_attendees;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * @param EE_Event $item
469
+	 * @return float
470
+	 * @throws EE_Error
471
+	 * @throws InvalidArgumentException
472
+	 * @throws InvalidDataTypeException
473
+	 * @throws InvalidInterfaceException
474
+	 */
475
+	public function column_tkts_sold(EE_Event $item)
476
+	{
477
+		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * @param EE_Event $item
484
+	 * @return string
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 */
490
+	public function column_actions(EE_Event $item)
491
+	{
492
+		//todo: remove when attendees is active
493
+		if (! defined('REG_ADMIN_URL')) {
494
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
495
+		}
496
+		$action_links = array();
497
+		$view_link = get_permalink($item->ID());
498
+		$action_links[] = '<a href="' . $view_link . '"'
499
+						 . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
500
+		$action_links[] = '<div class="dashicons dashicons-search"></div></a>';
501
+		if (EE_Registry::instance()->CAP->current_user_can(
502
+			'ee_edit_event',
503
+			'espresso_events_edit',
504
+			$item->ID()
505
+		)) {
506
+			$edit_query_args = array(
507
+				'action' => 'edit',
508
+				'post'   => $item->ID(),
509
+			);
510
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
511
+			$action_links[] = '<a href="' . $edit_link . '"'
512
+							 . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
513
+							 . '<div class="ee-icon ee-icon-calendar-edit"></div>'
514
+							 . '</a>';
515
+		}
516
+		if (
517
+			EE_Registry::instance()->CAP->current_user_can(
518
+				'ee_read_registrations',
519
+				'espresso_registrations_view_registration'
520
+			) && EE_Registry::instance()->CAP->current_user_can(
521
+				'ee_read_event',
522
+				'espresso_registrations_view_registration',
523
+				$item->ID()
524
+			)
525
+		) {
526
+			$attendees_query_args = array(
527
+				'action'   => 'default',
528
+				'event_id' => $item->ID(),
529
+			);
530
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
531
+			$action_links[] = '<a href="' . $attendees_link . '"'
532
+							 . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
533
+							 . '<div class="dashicons dashicons-groups"></div>'
534
+							 . '</a>';
535
+		}
536
+		$action_links = apply_filters(
537
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
538
+			$action_links,
539
+			$item
540
+		);
541
+		return $this->_action_string(
542
+			implode("\n\t", $action_links),
543
+			$item,
544
+			'div'
545
+		);
546
+	}
547 547
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_EE_Registrations_List_Table.class.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -15,115 +15,115 @@
 block discarded – undo
15 15
 class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @param EE_Registration $item
20
-     * @return string
21
-     * @throws EE_Error
22
-     * @throws InvalidArgumentException
23
-     * @throws ReflectionException
24
-     * @throws InvalidDataTypeException
25
-     * @throws InvalidInterfaceException
26
-     */
27
-    function column__REG_date(EE_Registration $item)
28
-    {
29
-        $date_linked = parent::column__REG_date($item);
30
-        $actions = array();
31
-        //Build row actions
32
-        $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array(
33
-            'action'   => 'event_registrations',
34
-            'event_id' => $item->event_ID(),
35
-        ), REG_ADMIN_URL);
36
-        $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can(
37
-            'ee_read_registration',
38
-            'espresso_registrations_registration_checkins',
39
-            $item->ID()
40
-        ) && EE_Registry::instance()->CAP->current_user_can(
41
-            'ee_read_checkins',
42
-            'espresso_registrations_registration_checkins'
43
-        )
44
-            ? '<a href="' . $check_in_url . '"'
45
-              . ' title="' . esc_attr__(
46
-                  'The Check-In List allows you to easily toggle check-in status for this event',
47
-                  'event_espresso'
48
-              )
49
-              . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>'
50
-            : esc_html__('View Check-ins', 'event_espresso');
18
+	/**
19
+	 * @param EE_Registration $item
20
+	 * @return string
21
+	 * @throws EE_Error
22
+	 * @throws InvalidArgumentException
23
+	 * @throws ReflectionException
24
+	 * @throws InvalidDataTypeException
25
+	 * @throws InvalidInterfaceException
26
+	 */
27
+	function column__REG_date(EE_Registration $item)
28
+	{
29
+		$date_linked = parent::column__REG_date($item);
30
+		$actions = array();
31
+		//Build row actions
32
+		$check_in_url = EE_Admin_Page::add_query_args_and_nonce(array(
33
+			'action'   => 'event_registrations',
34
+			'event_id' => $item->event_ID(),
35
+		), REG_ADMIN_URL);
36
+		$actions['check_in'] = EE_Registry::instance()->CAP->current_user_can(
37
+			'ee_read_registration',
38
+			'espresso_registrations_registration_checkins',
39
+			$item->ID()
40
+		) && EE_Registry::instance()->CAP->current_user_can(
41
+			'ee_read_checkins',
42
+			'espresso_registrations_registration_checkins'
43
+		)
44
+			? '<a href="' . $check_in_url . '"'
45
+			  . ' title="' . esc_attr__(
46
+				  'The Check-In List allows you to easily toggle check-in status for this event',
47
+				  'event_espresso'
48
+			  )
49
+			  . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>'
50
+			: esc_html__('View Check-ins', 'event_espresso');
51 51
 
52
-        return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions));
53
-    }
52
+		return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions));
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     *        column_default
58
-     *
59
-     * @param \EE_Registration $item
60
-     * @return string
61
-     * @throws EE_Error
62
-     * @throws InvalidArgumentException
63
-     * @throws InvalidDataTypeException
64
-     * @throws InvalidInterfaceException
65
-     * @throws ReflectionException
66
-     */
67
-    public function column_DTT_EVT_start(EE_Registration $item)
68
-    {
69
-        $remove_defaults = array('default_where_conditions' => 'none');
70
-        $ticket = $item->ticket();
71
-        $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array();
72
-        $EVT_ID = $item->event_ID();
73
-        $datetimes_for_display = array();
74
-        foreach ($datetimes as $datetime) {
75
-            $datetime_string = '';
76
-            if (EE_Registry::instance()->CAP->current_user_can(
77
-                'ee_read_checkin',
78
-                'espresso_registrations_registration_checkins',
79
-                $item->ID()
80
-            )) {
81
-                // open "a" tag and "href"
82
-                $datetime_string .= '<a href="';
83
-                // checkin URL
84
-                $datetime_string .= EE_Admin_Page::add_query_args_and_nonce(
85
-                    array(
86
-                        'action'   => 'event_registrations',
87
-                        'event_id' => $EVT_ID,
88
-                        'DTT_ID'   => $datetime->ID(),
89
-                    ),
90
-                    REG_ADMIN_URL
91
-                );
92
-                // close "href"
93
-                $datetime_string .= '"';
94
-                // open "title" tag
95
-                $datetime_string .= ' title="';
96
-                // link title text
97
-                $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso');
98
-                // close "title" tag and end of "a" tag opening
99
-                $datetime_string .= '">';
100
-                // link text
101
-                $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
102
-                // close "a" tag
103
-                $datetime_string .= '</a>';
104
-            } else {
105
-                $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
106
-            }
107
-            // add a "View Registrations" link that filters list by event AND datetime
108
-            $datetime_string .= $this->row_actions(
109
-                array(
110
-                    'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
111
-                        array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()),
112
-                        REG_ADMIN_URL
113
-                    )
114
-                           . '" title="' . sprintf(
115
-                               esc_attr__(
116
-                                   'Filter this list to only show registrations for this datetime %s',
117
-                                   'event_espresso'
118
-                               ),
119
-                               $datetime->name()
120
-                           ) . '">'
121
-                           . esc_html__('View Registrations', 'event_espresso')
122
-                           . '</a>',
123
-                )
124
-            );
125
-            $datetimes_for_display[] = $datetime_string;
126
-        }
127
-        return $this->generateDisplayForDateTimes($datetimes_for_display);
128
-    }
56
+	/**
57
+	 *        column_default
58
+	 *
59
+	 * @param \EE_Registration $item
60
+	 * @return string
61
+	 * @throws EE_Error
62
+	 * @throws InvalidArgumentException
63
+	 * @throws InvalidDataTypeException
64
+	 * @throws InvalidInterfaceException
65
+	 * @throws ReflectionException
66
+	 */
67
+	public function column_DTT_EVT_start(EE_Registration $item)
68
+	{
69
+		$remove_defaults = array('default_where_conditions' => 'none');
70
+		$ticket = $item->ticket();
71
+		$datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array();
72
+		$EVT_ID = $item->event_ID();
73
+		$datetimes_for_display = array();
74
+		foreach ($datetimes as $datetime) {
75
+			$datetime_string = '';
76
+			if (EE_Registry::instance()->CAP->current_user_can(
77
+				'ee_read_checkin',
78
+				'espresso_registrations_registration_checkins',
79
+				$item->ID()
80
+			)) {
81
+				// open "a" tag and "href"
82
+				$datetime_string .= '<a href="';
83
+				// checkin URL
84
+				$datetime_string .= EE_Admin_Page::add_query_args_and_nonce(
85
+					array(
86
+						'action'   => 'event_registrations',
87
+						'event_id' => $EVT_ID,
88
+						'DTT_ID'   => $datetime->ID(),
89
+					),
90
+					REG_ADMIN_URL
91
+				);
92
+				// close "href"
93
+				$datetime_string .= '"';
94
+				// open "title" tag
95
+				$datetime_string .= ' title="';
96
+				// link title text
97
+				$datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso');
98
+				// close "title" tag and end of "a" tag opening
99
+				$datetime_string .= '">';
100
+				// link text
101
+				$datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
102
+				// close "a" tag
103
+				$datetime_string .= '</a>';
104
+			} else {
105
+				$datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start');
106
+			}
107
+			// add a "View Registrations" link that filters list by event AND datetime
108
+			$datetime_string .= $this->row_actions(
109
+				array(
110
+					'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
111
+						array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()),
112
+						REG_ADMIN_URL
113
+					)
114
+						   . '" title="' . sprintf(
115
+							   esc_attr__(
116
+								   'Filter this list to only show registrations for this datetime %s',
117
+								   'event_espresso'
118
+							   ),
119
+							   $datetime->name()
120
+						   ) . '">'
121
+						   . esc_html__('View Registrations', 'event_espresso')
122
+						   . '</a>',
123
+				)
124
+			);
125
+			$datetimes_for_display[] = $datetime_string;
126
+		}
127
+		return $this->generateDisplayForDateTimes($datetimes_for_display);
128
+	}
129 129
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
             'ee_read_checkins',
42 42
             'espresso_registrations_registration_checkins'
43 43
         )
44
-            ? '<a href="' . $check_in_url . '"'
45
-              . ' title="' . esc_attr__(
44
+            ? '<a href="'.$check_in_url.'"'
45
+              . ' title="'.esc_attr__(
46 46
                   'The Check-In List allows you to easily toggle check-in status for this event',
47 47
                   'event_espresso'
48 48
               )
49
-              . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>'
49
+              . '">'.esc_html__('View Check-ins', 'event_espresso').'</a>'
50 50
             : esc_html__('View Check-ins', 'event_espresso');
51 51
 
52 52
         return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions));
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
             // add a "View Registrations" link that filters list by event AND datetime
108 108
             $datetime_string .= $this->row_actions(
109 109
                 array(
110
-                    'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
110
+                    'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
111 111
                         array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()),
112 112
                         REG_ADMIN_URL
113 113
                     )
114
-                           . '" title="' . sprintf(
114
+                           . '" title="'.sprintf(
115 115
                                esc_attr__(
116 116
                                    'Filter this list to only show registrations for this datetime %s',
117 117
                                    'event_espresso'
118 118
                                ),
119 119
                                $datetime->name()
120
-                           ) . '">'
120
+                           ).'">'
121 121
                            . esc_html__('View Registrations', 'event_espresso')
122 122
                            . '</a>',
123 123
                 )
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 2 patches
Indentation   +926 added lines, -926 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 
5 5
 if (! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('No direct script access allowed');
6
+	exit('No direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -28,1006 +28,1006 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * @var array
33
-     */
34
-    private $_status;
31
+	/**
32
+	 * @var array
33
+	 */
34
+	private $_status;
35 35
 
36 36
 
37
-    /**
38
-     * An array of transaction details for the related transaction to the registration being processed.
39
-     * This is set via the _set_related_details method.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $_transaction_details = array();
37
+	/**
38
+	 * An array of transaction details for the related transaction to the registration being processed.
39
+	 * This is set via the _set_related_details method.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $_transaction_details = array();
44 44
 
45 45
 
46
-    /**
47
-     * An array of event details for the related event to the registration being processed.
48
-     * This is set via the _set_related_details method.
49
-     *
50
-     * @var array
51
-     */
52
-    protected $_event_details = array();
46
+	/**
47
+	 * An array of event details for the related event to the registration being processed.
48
+	 * This is set via the _set_related_details method.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	protected $_event_details = array();
53 53
 
54 54
 
55
-    /**
56
-     * @param \Registrations_Admin_Page $admin_page
57
-     */
58
-    public function __construct(Registrations_Admin_Page $admin_page)
59
-    {
60
-        if (! empty($_GET['event_id'])) {
61
-            $extra_query_args = array();
62
-            foreach ($admin_page->get_views() as $key => $view_details) {
63
-                $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
64
-            }
65
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
66
-        }
67
-        parent::__construct($admin_page);
68
-        $this->_status = $this->_admin_page->get_registration_status_array();
69
-    }
55
+	/**
56
+	 * @param \Registrations_Admin_Page $admin_page
57
+	 */
58
+	public function __construct(Registrations_Admin_Page $admin_page)
59
+	{
60
+		if (! empty($_GET['event_id'])) {
61
+			$extra_query_args = array();
62
+			foreach ($admin_page->get_views() as $key => $view_details) {
63
+				$extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
64
+			}
65
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
66
+		}
67
+		parent::__construct($admin_page);
68
+		$this->_status = $this->_admin_page->get_registration_status_array();
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     *    _setup_data
74
-     *
75
-     * @access protected
76
-     * @return void
77
-     */
78
-    protected function _setup_data()
79
-    {
80
-        $this->_data = $this->_admin_page->get_registrations($this->_per_page);
81
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
82
-    }
72
+	/**
73
+	 *    _setup_data
74
+	 *
75
+	 * @access protected
76
+	 * @return void
77
+	 */
78
+	protected function _setup_data()
79
+	{
80
+		$this->_data = $this->_admin_page->get_registrations($this->_per_page);
81
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     *    _set_properties
87
-     *
88
-     * @access protected
89
-     * @return void
90
-     */
91
-    protected function _set_properties()
92
-    {
93
-        $this->_wp_list_args = array(
94
-            'singular' => __('registration', 'event_espresso'),
95
-            'plural'   => __('registrations', 'event_espresso'),
96
-            'ajax'     => true,
97
-            'screen'   => $this->_admin_page->get_current_screen()->id,
98
-        );
99
-        $ID_column_name = __('ID', 'event_espresso');
100
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
101
-        $ID_column_name .= __('Registrant Name', 'event_espresso');
102
-        $ID_column_name .= '</span> ';
103
-        if (isset($_GET['event_id'])) {
104
-            $this->_columns = array(
105
-                'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
106
-                '_REG_ID'          => $ID_column_name,
107
-                'ATT_fname'        => __('Name', 'event_espresso'),
108
-                'ATT_email'        => __('Email', 'event_espresso'),
109
-                '_REG_date'        => __('Reg Date', 'event_espresso'),
110
-                'PRC_amount'       => __('TKT Price', 'event_espresso'),
111
-                '_REG_final_price' => __('Final Price', 'event_espresso'),
112
-                'TXN_total'        => __('Total Txn', 'event_espresso'),
113
-                'TXN_paid'         => __('Paid', 'event_espresso'),
114
-                'actions'          => __('Actions', 'event_espresso'),
115
-            );
116
-            $this->_bottom_buttons = array(
117
-                'report' => array(
118
-                    'route'         => 'registrations_report',
119
-                    'extra_request' => array(
120
-                        'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
121
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
122
-                    ),
123
-                ),
124
-            );
125
-        } else {
126
-            $this->_columns = array(
127
-                'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
128
-                '_REG_ID'          => $ID_column_name,
129
-                'ATT_fname'        => __('Name', 'event_espresso'),
130
-                '_REG_date'        => __('TXN Date', 'event_espresso'),
131
-                'event_name'       => __('Event', 'event_espresso'),
132
-                'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
133
-                '_REG_final_price' => __('Price', 'event_espresso'),
134
-                '_REG_paid'        => __('Paid', 'event_espresso'),
135
-                'actions'          => __('Actions', 'event_espresso'),
136
-            );
137
-            $this->_bottom_buttons = array(
138
-                'report_all' => array(
139
-                    'route'         => 'registrations_report',
140
-                    'extra_request' => array(
141
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
142
-                    ),
143
-                ),
144
-            );
145
-        }
146
-        $this->_bottom_buttons['report_filtered'] = array(
147
-            'route'         => 'registrations_report',
148
-            'extra_request' => array(
149
-                'use_filters' => true,
150
-                'filters'     => array_diff_key($this->_req_data, array_flip(array(
151
-                    'page',
152
-                    'action',
153
-                    'default_nonce',
154
-                ))),
155
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
156
-            ),
157
-        );
158
-        $this->_primary_column = '_REG_ID';
159
-        $this->_sortable_columns = array(
160
-            '_REG_date'     => array('_REG_date' => true),   //true means its already sorted
161
-            /**
162
-             * Allows users to change the default sort if they wish.
163
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
164
-             * name.
165
-             */
166
-            'ATT_fname'     => array(
167
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
168
-                true,
169
-                $this,
170
-            )
171
-                ? array('ATT_lname' => false)
172
-                : array('ATT_fname' => false),
173
-            'event_name'    => array('event_name' => false),
174
-            'DTT_EVT_start' => array('DTT_EVT_start' => false),
175
-            '_REG_ID'       => array('_REG_ID' => false),
176
-        );
177
-        $this->_hidden_columns = array();
178
-    }
85
+	/**
86
+	 *    _set_properties
87
+	 *
88
+	 * @access protected
89
+	 * @return void
90
+	 */
91
+	protected function _set_properties()
92
+	{
93
+		$this->_wp_list_args = array(
94
+			'singular' => __('registration', 'event_espresso'),
95
+			'plural'   => __('registrations', 'event_espresso'),
96
+			'ajax'     => true,
97
+			'screen'   => $this->_admin_page->get_current_screen()->id,
98
+		);
99
+		$ID_column_name = __('ID', 'event_espresso');
100
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
101
+		$ID_column_name .= __('Registrant Name', 'event_espresso');
102
+		$ID_column_name .= '</span> ';
103
+		if (isset($_GET['event_id'])) {
104
+			$this->_columns = array(
105
+				'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
106
+				'_REG_ID'          => $ID_column_name,
107
+				'ATT_fname'        => __('Name', 'event_espresso'),
108
+				'ATT_email'        => __('Email', 'event_espresso'),
109
+				'_REG_date'        => __('Reg Date', 'event_espresso'),
110
+				'PRC_amount'       => __('TKT Price', 'event_espresso'),
111
+				'_REG_final_price' => __('Final Price', 'event_espresso'),
112
+				'TXN_total'        => __('Total Txn', 'event_espresso'),
113
+				'TXN_paid'         => __('Paid', 'event_espresso'),
114
+				'actions'          => __('Actions', 'event_espresso'),
115
+			);
116
+			$this->_bottom_buttons = array(
117
+				'report' => array(
118
+					'route'         => 'registrations_report',
119
+					'extra_request' => array(
120
+						'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
121
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
122
+					),
123
+				),
124
+			);
125
+		} else {
126
+			$this->_columns = array(
127
+				'cb'               => '<input type="checkbox" />', //Render a checkbox instead of text
128
+				'_REG_ID'          => $ID_column_name,
129
+				'ATT_fname'        => __('Name', 'event_espresso'),
130
+				'_REG_date'        => __('TXN Date', 'event_espresso'),
131
+				'event_name'       => __('Event', 'event_espresso'),
132
+				'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
133
+				'_REG_final_price' => __('Price', 'event_espresso'),
134
+				'_REG_paid'        => __('Paid', 'event_espresso'),
135
+				'actions'          => __('Actions', 'event_espresso'),
136
+			);
137
+			$this->_bottom_buttons = array(
138
+				'report_all' => array(
139
+					'route'         => 'registrations_report',
140
+					'extra_request' => array(
141
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
142
+					),
143
+				),
144
+			);
145
+		}
146
+		$this->_bottom_buttons['report_filtered'] = array(
147
+			'route'         => 'registrations_report',
148
+			'extra_request' => array(
149
+				'use_filters' => true,
150
+				'filters'     => array_diff_key($this->_req_data, array_flip(array(
151
+					'page',
152
+					'action',
153
+					'default_nonce',
154
+				))),
155
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
156
+			),
157
+		);
158
+		$this->_primary_column = '_REG_ID';
159
+		$this->_sortable_columns = array(
160
+			'_REG_date'     => array('_REG_date' => true),   //true means its already sorted
161
+			/**
162
+			 * Allows users to change the default sort if they wish.
163
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
164
+			 * name.
165
+			 */
166
+			'ATT_fname'     => array(
167
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
168
+				true,
169
+				$this,
170
+			)
171
+				? array('ATT_lname' => false)
172
+				: array('ATT_fname' => false),
173
+			'event_name'    => array('event_name' => false),
174
+			'DTT_EVT_start' => array('DTT_EVT_start' => false),
175
+			'_REG_ID'       => array('_REG_ID' => false),
176
+		);
177
+		$this->_hidden_columns = array();
178
+	}
179 179
 
180 180
 
181
-    /**
182
-     * This simply sets up the row class for the table rows.
183
-     * Allows for easier overriding of child methods for setting up sorting.
184
-     *
185
-     * @param  EE_Registration $item the current item
186
-     * @return string
187
-     */
188
-    protected function _get_row_class($item)
189
-    {
190
-        $class = parent::_get_row_class($item);
191
-        //add status class
192
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
193
-        if ($this->_has_checkbox_column) {
194
-            $class .= ' has-checkbox-column';
195
-        }
196
-        return $class;
197
-    }
181
+	/**
182
+	 * This simply sets up the row class for the table rows.
183
+	 * Allows for easier overriding of child methods for setting up sorting.
184
+	 *
185
+	 * @param  EE_Registration $item the current item
186
+	 * @return string
187
+	 */
188
+	protected function _get_row_class($item)
189
+	{
190
+		$class = parent::_get_row_class($item);
191
+		//add status class
192
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
193
+		if ($this->_has_checkbox_column) {
194
+			$class .= ' has-checkbox-column';
195
+		}
196
+		return $class;
197
+	}
198 198
 
199 199
 
200
-    /**
201
-     * Set the $_transaction_details property if not set yet.
202
-     *
203
-     * @param EE_Registration $registration
204
-     * @throws EE_Error
205
-     * @throws InvalidArgumentException
206
-     * @throws ReflectionException
207
-     * @throws InvalidDataTypeException
208
-     * @throws InvalidInterfaceException
209
-     */
210
-    protected function _set_related_details(EE_Registration $registration)
211
-    {
212
-        $transaction = $registration->get_first_related('Transaction');
213
-        $status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
214
-            : EEM_Transaction::failed_status_code;
215
-        $this->_transaction_details = array(
216
-            'transaction' => $transaction,
217
-            'status'      => $status,
218
-            'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
219
-            'title_attr'  => sprintf(
220
-                __('View Transaction Details (%s)', 'event_espresso'),
221
-                EEH_Template::pretty_status($status, false, 'sentence')
222
-            ),
223
-        );
224
-        try {
225
-            $event = $registration->event();
226
-        } catch (EntityNotFoundException $e) {
227
-            $event = null;
228
-        }
229
-        $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
230
-        $this->_event_details = array(
231
-            'event'      => $event,
232
-            'status'     => $status,
233
-            'id'         => $event instanceof EE_Event ? $event->ID() : 0,
234
-            'title_attr' => sprintf(
235
-                __('Edit Event (%s)', 'event_espresso'),
236
-                EEH_Template::pretty_status($status, false, 'sentence')
237
-            ),
238
-        );
239
-    }
200
+	/**
201
+	 * Set the $_transaction_details property if not set yet.
202
+	 *
203
+	 * @param EE_Registration $registration
204
+	 * @throws EE_Error
205
+	 * @throws InvalidArgumentException
206
+	 * @throws ReflectionException
207
+	 * @throws InvalidDataTypeException
208
+	 * @throws InvalidInterfaceException
209
+	 */
210
+	protected function _set_related_details(EE_Registration $registration)
211
+	{
212
+		$transaction = $registration->get_first_related('Transaction');
213
+		$status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
214
+			: EEM_Transaction::failed_status_code;
215
+		$this->_transaction_details = array(
216
+			'transaction' => $transaction,
217
+			'status'      => $status,
218
+			'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
219
+			'title_attr'  => sprintf(
220
+				__('View Transaction Details (%s)', 'event_espresso'),
221
+				EEH_Template::pretty_status($status, false, 'sentence')
222
+			),
223
+		);
224
+		try {
225
+			$event = $registration->event();
226
+		} catch (EntityNotFoundException $e) {
227
+			$event = null;
228
+		}
229
+		$status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
230
+		$this->_event_details = array(
231
+			'event'      => $event,
232
+			'status'     => $status,
233
+			'id'         => $event instanceof EE_Event ? $event->ID() : 0,
234
+			'title_attr' => sprintf(
235
+				__('Edit Event (%s)', 'event_espresso'),
236
+				EEH_Template::pretty_status($status, false, 'sentence')
237
+			),
238
+		);
239
+	}
240 240
 
241 241
 
242
-    /**
243
-     *    _get_table_filters
244
-     *
245
-     * @access protected
246
-     * @return array
247
-     */
248
-    protected function _get_table_filters()
249
-    {
250
-        $filters = array();
251
-        //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
252
-        // methods.
253
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
254
-        $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
255
-        $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
256
-        $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
257
-        $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
258
-        $status = array();
259
-        $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
260
-        foreach ($this->_status as $key => $value) {
261
-            $status[] = array('id' => $key, 'text' => $value);
262
-        }
263
-        if ($this->_view !== 'incomplete') {
264
-            $filters[] = EEH_Form_Fields::select_input(
265
-                '_reg_status',
266
-                $status,
267
-                isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
268
-                    : ''
269
-            );
270
-        }
271
-        if (isset($this->_req_data['event_id'])) {
272
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
273
-        }
274
-        return $filters;
275
-    }
242
+	/**
243
+	 *    _get_table_filters
244
+	 *
245
+	 * @access protected
246
+	 * @return array
247
+	 */
248
+	protected function _get_table_filters()
249
+	{
250
+		$filters = array();
251
+		//todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
252
+		// methods.
253
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
254
+		$cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
255
+		$reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
256
+		$filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
257
+		$filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
258
+		$status = array();
259
+		$status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
260
+		foreach ($this->_status as $key => $value) {
261
+			$status[] = array('id' => $key, 'text' => $value);
262
+		}
263
+		if ($this->_view !== 'incomplete') {
264
+			$filters[] = EEH_Form_Fields::select_input(
265
+				'_reg_status',
266
+				$status,
267
+				isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
268
+					: ''
269
+			);
270
+		}
271
+		if (isset($this->_req_data['event_id'])) {
272
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
273
+		}
274
+		return $filters;
275
+	}
276 276
 
277 277
 
278
-    /**
279
-     *    _add_view_counts
280
-     *
281
-     * @access protected
282
-     * @return void
283
-     * @throws EE_Error
284
-     * @throws InvalidArgumentException
285
-     * @throws InvalidDataTypeException
286
-     * @throws InvalidInterfaceException
287
-     */
288
-    protected function _add_view_counts()
289
-    {
290
-        $this->_views['all']['count'] = $this->_total_registrations();
291
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
292
-        $this->_views['today']['count'] = $this->_total_registrations_today();
293
-        if (EE_Registry::instance()->CAP->current_user_can(
294
-            'ee_delete_registrations',
295
-            'espresso_registrations_trash_registrations'
296
-        )) {
297
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
298
-            $this->_views['trash']['count'] = $this->_total_registrations('trash');
299
-        }
300
-    }
278
+	/**
279
+	 *    _add_view_counts
280
+	 *
281
+	 * @access protected
282
+	 * @return void
283
+	 * @throws EE_Error
284
+	 * @throws InvalidArgumentException
285
+	 * @throws InvalidDataTypeException
286
+	 * @throws InvalidInterfaceException
287
+	 */
288
+	protected function _add_view_counts()
289
+	{
290
+		$this->_views['all']['count'] = $this->_total_registrations();
291
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
292
+		$this->_views['today']['count'] = $this->_total_registrations_today();
293
+		if (EE_Registry::instance()->CAP->current_user_can(
294
+			'ee_delete_registrations',
295
+			'espresso_registrations_trash_registrations'
296
+		)) {
297
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
298
+			$this->_views['trash']['count'] = $this->_total_registrations('trash');
299
+		}
300
+	}
301 301
 
302 302
 
303
-    /**
304
-     * _total_registrations
305
-     *
306
-     * @access protected
307
-     * @param string $view
308
-     * @return int
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
314
-    protected function _total_registrations($view = '')
315
-    {
316
-        $_where = array();
317
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
318
-        if ($EVT_ID) {
319
-            $_where['EVT_ID'] = $EVT_ID;
320
-        }
321
-        switch ($view) {
322
-            case 'trash':
323
-                return EEM_Registration::instance()->count_deleted(array($_where));
324
-                break;
325
-            case 'incomplete':
326
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
327
-                break;
328
-            default:
329
-                $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
330
-        }
331
-        return EEM_Registration::instance()->count(array($_where));
332
-    }
303
+	/**
304
+	 * _total_registrations
305
+	 *
306
+	 * @access protected
307
+	 * @param string $view
308
+	 * @return int
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314
+	protected function _total_registrations($view = '')
315
+	{
316
+		$_where = array();
317
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
318
+		if ($EVT_ID) {
319
+			$_where['EVT_ID'] = $EVT_ID;
320
+		}
321
+		switch ($view) {
322
+			case 'trash':
323
+				return EEM_Registration::instance()->count_deleted(array($_where));
324
+				break;
325
+			case 'incomplete':
326
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
327
+				break;
328
+			default:
329
+				$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
330
+		}
331
+		return EEM_Registration::instance()->count(array($_where));
332
+	}
333 333
 
334 334
 
335
-    /**
336
-     * _total_registrations_this_month
337
-     *
338
-     * @access protected
339
-     * @return int
340
-     * @throws EE_Error
341
-     * @throws InvalidArgumentException
342
-     * @throws InvalidDataTypeException
343
-     * @throws InvalidInterfaceException
344
-     */
345
-    protected function _total_registrations_this_month()
346
-    {
347
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
348
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
349
-        $this_year_r = date('Y', current_time('timestamp'));
350
-        $time_start = ' 00:00:00';
351
-        $time_end = ' 23:59:59';
352
-        $this_month_r = date('m', current_time('timestamp'));
353
-        $days_this_month = date('t', current_time('timestamp'));
354
-        //setup date query.
355
-        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
356
-            'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
358
-            'Y-m-d H:i:s'
359
-        );
360
-        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
361
-            'REG_date',
362
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
363
-            'Y-m-d H:i:s'
364
-        );
365
-        $_where['REG_date'] = array(
366
-            'BETWEEN',
367
-            array(
368
-                $beginning_string,
369
-                $end_string,
370
-            ),
371
-        );
372
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
373
-        return EEM_Registration::instance()->count(array($_where));
374
-    }
335
+	/**
336
+	 * _total_registrations_this_month
337
+	 *
338
+	 * @access protected
339
+	 * @return int
340
+	 * @throws EE_Error
341
+	 * @throws InvalidArgumentException
342
+	 * @throws InvalidDataTypeException
343
+	 * @throws InvalidInterfaceException
344
+	 */
345
+	protected function _total_registrations_this_month()
346
+	{
347
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
348
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
349
+		$this_year_r = date('Y', current_time('timestamp'));
350
+		$time_start = ' 00:00:00';
351
+		$time_end = ' 23:59:59';
352
+		$this_month_r = date('m', current_time('timestamp'));
353
+		$days_this_month = date('t', current_time('timestamp'));
354
+		//setup date query.
355
+		$beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
356
+			'REG_date',
357
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
358
+			'Y-m-d H:i:s'
359
+		);
360
+		$end_string = EEM_Registration::instance()->convert_datetime_for_query(
361
+			'REG_date',
362
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
363
+			'Y-m-d H:i:s'
364
+		);
365
+		$_where['REG_date'] = array(
366
+			'BETWEEN',
367
+			array(
368
+				$beginning_string,
369
+				$end_string,
370
+			),
371
+		);
372
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
373
+		return EEM_Registration::instance()->count(array($_where));
374
+	}
375 375
 
376 376
 
377
-    /**
378
-     * _total_registrations_today
379
-     *
380
-     * @access protected
381
-     * @return int
382
-     * @throws EE_Error
383
-     * @throws InvalidArgumentException
384
-     * @throws InvalidDataTypeException
385
-     * @throws InvalidInterfaceException
386
-     */
387
-    protected function _total_registrations_today()
388
-    {
389
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
390
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
391
-        $current_date = date('Y-m-d', current_time('timestamp'));
392
-        $time_start = ' 00:00:00';
393
-        $time_end = ' 23:59:59';
394
-        $_where['REG_date'] = array(
395
-            'BETWEEN',
396
-            array(
397
-                EEM_Registration::instance()->convert_datetime_for_query(
398
-                    'REG_date',
399
-                    $current_date . $time_start,
400
-                    'Y-m-d H:i:s'
401
-                ),
402
-                EEM_Registration::instance()->convert_datetime_for_query(
403
-                    'REG_date',
404
-                    $current_date . $time_end,
405
-                    'Y-m-d H:i:s'
406
-                ),
407
-            ),
408
-        );
409
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
410
-        return EEM_Registration::instance()->count(array($_where));
411
-    }
377
+	/**
378
+	 * _total_registrations_today
379
+	 *
380
+	 * @access protected
381
+	 * @return int
382
+	 * @throws EE_Error
383
+	 * @throws InvalidArgumentException
384
+	 * @throws InvalidDataTypeException
385
+	 * @throws InvalidInterfaceException
386
+	 */
387
+	protected function _total_registrations_today()
388
+	{
389
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
390
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
391
+		$current_date = date('Y-m-d', current_time('timestamp'));
392
+		$time_start = ' 00:00:00';
393
+		$time_end = ' 23:59:59';
394
+		$_where['REG_date'] = array(
395
+			'BETWEEN',
396
+			array(
397
+				EEM_Registration::instance()->convert_datetime_for_query(
398
+					'REG_date',
399
+					$current_date . $time_start,
400
+					'Y-m-d H:i:s'
401
+				),
402
+				EEM_Registration::instance()->convert_datetime_for_query(
403
+					'REG_date',
404
+					$current_date . $time_end,
405
+					'Y-m-d H:i:s'
406
+				),
407
+			),
408
+		);
409
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
410
+		return EEM_Registration::instance()->count(array($_where));
411
+	}
412 412
 
413 413
 
414
-    /**
415
-     * column_cb
416
-     *
417
-     * @access public
418
-     * @param \EE_Registration $item
419
-     * @return string
420
-     * @throws EE_Error
421
-     * @throws InvalidArgumentException
422
-     * @throws InvalidDataTypeException
423
-     * @throws InvalidInterfaceException
424
-     * @throws ReflectionException
425
-     */
426
-    public function column_cb($item)
427
-    {
428
-        /** checkbox/lock **/
429
-        $transaction = $item->get_first_related('Transaction');
430
-        $payment_count = $transaction instanceof EE_Transaction
431
-            ? $transaction->count_related('Payment')
432
-            : 0;
433
-        return $payment_count > 0
434
-               || ! EE_Registry::instance()->CAP->current_user_can(
435
-                   'ee_edit_registration',
436
-                   'registration_list_table_checkbox_input',
437
-                   $item->ID()
438
-               )
439
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
440
-              . '<span class="ee-lock-icon"></span>'
441
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
442
-    }
414
+	/**
415
+	 * column_cb
416
+	 *
417
+	 * @access public
418
+	 * @param \EE_Registration $item
419
+	 * @return string
420
+	 * @throws EE_Error
421
+	 * @throws InvalidArgumentException
422
+	 * @throws InvalidDataTypeException
423
+	 * @throws InvalidInterfaceException
424
+	 * @throws ReflectionException
425
+	 */
426
+	public function column_cb($item)
427
+	{
428
+		/** checkbox/lock **/
429
+		$transaction = $item->get_first_related('Transaction');
430
+		$payment_count = $transaction instanceof EE_Transaction
431
+			? $transaction->count_related('Payment')
432
+			: 0;
433
+		return $payment_count > 0
434
+			   || ! EE_Registry::instance()->CAP->current_user_can(
435
+				   'ee_edit_registration',
436
+				   'registration_list_table_checkbox_input',
437
+				   $item->ID()
438
+			   )
439
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
440
+			  . '<span class="ee-lock-icon"></span>'
441
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
442
+	}
443 443
 
444 444
 
445
-    /**
446
-     * column__REG_ID
447
-     *
448
-     * @access public
449
-     * @param \EE_Registration $item
450
-     * @return string
451
-     * @throws EE_Error
452
-     * @throws InvalidArgumentException
453
-     * @throws InvalidDataTypeException
454
-     * @throws InvalidInterfaceException
455
-     * @throws ReflectionException
456
-     */
457
-    public function column__REG_ID(EE_Registration $item)
458
-    {
459
-        $attendee = $item->attendee();
460
-        $content = $item->ID();
461
-        $content .= '<div class="show-on-mobile-view-only">';
462
-        $content .= '<br>';
463
-        $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
464
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
466
-        $content .= '</div>';
467
-        return $content;
468
-    }
445
+	/**
446
+	 * column__REG_ID
447
+	 *
448
+	 * @access public
449
+	 * @param \EE_Registration $item
450
+	 * @return string
451
+	 * @throws EE_Error
452
+	 * @throws InvalidArgumentException
453
+	 * @throws InvalidDataTypeException
454
+	 * @throws InvalidInterfaceException
455
+	 * @throws ReflectionException
456
+	 */
457
+	public function column__REG_ID(EE_Registration $item)
458
+	{
459
+		$attendee = $item->attendee();
460
+		$content = $item->ID();
461
+		$content .= '<div class="show-on-mobile-view-only">';
462
+		$content .= '<br>';
463
+		$content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
464
+		$content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
+		$content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
466
+		$content .= '</div>';
467
+		return $content;
468
+	}
469 469
 
470 470
 
471
-    /**
472
-     * column__REG_date
473
-     *
474
-     * @access public
475
-     * @param \EE_Registration $item
476
-     * @return string
477
-     * @throws EE_Error
478
-     * @throws InvalidArgumentException
479
-     * @throws InvalidDataTypeException
480
-     * @throws InvalidInterfaceException
481
-     * @throws ReflectionException
482
-     */
483
-    public function column__REG_date(EE_Registration $item)
484
-    {
485
-        $this->_set_related_details($item);
486
-        //Build row actions
487
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
488
-            'action' => 'view_transaction',
489
-            'TXN_ID' => $this->_transaction_details['id'],
490
-        ), TXN_ADMIN_URL);
491
-        $view_link = EE_Registry::instance()->CAP->current_user_can(
492
-            'ee_read_transaction',
493
-            'espresso_transactions_view_transaction'
494
-        )
495
-            ? '<a class="ee-status-color-'
496
-                . $this->_transaction_details['status']
497
-                . '" href="'
498
-                . $view_lnk_url
499
-                . '" title="'
500
-                . esc_attr($this->_transaction_details['title_attr'])
501
-                . '">'
502
-                . $item->get_i18n_datetime('REG_date')
503
-                . '</a>' : $item->get_i18n_datetime('REG_date');
504
-        $view_link .= '<br><span class="ee-status-text-small">'
505
-                      . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
506
-                      . '</span>';
507
-        return $view_link;
508
-    }
471
+	/**
472
+	 * column__REG_date
473
+	 *
474
+	 * @access public
475
+	 * @param \EE_Registration $item
476
+	 * @return string
477
+	 * @throws EE_Error
478
+	 * @throws InvalidArgumentException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws InvalidInterfaceException
481
+	 * @throws ReflectionException
482
+	 */
483
+	public function column__REG_date(EE_Registration $item)
484
+	{
485
+		$this->_set_related_details($item);
486
+		//Build row actions
487
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
488
+			'action' => 'view_transaction',
489
+			'TXN_ID' => $this->_transaction_details['id'],
490
+		), TXN_ADMIN_URL);
491
+		$view_link = EE_Registry::instance()->CAP->current_user_can(
492
+			'ee_read_transaction',
493
+			'espresso_transactions_view_transaction'
494
+		)
495
+			? '<a class="ee-status-color-'
496
+				. $this->_transaction_details['status']
497
+				. '" href="'
498
+				. $view_lnk_url
499
+				. '" title="'
500
+				. esc_attr($this->_transaction_details['title_attr'])
501
+				. '">'
502
+				. $item->get_i18n_datetime('REG_date')
503
+				. '</a>' : $item->get_i18n_datetime('REG_date');
504
+		$view_link .= '<br><span class="ee-status-text-small">'
505
+					  . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
506
+					  . '</span>';
507
+		return $view_link;
508
+	}
509 509
 
510 510
 
511
-    /**
512
-     * column_event_name
513
-     *
514
-     * @access public
515
-     * @param \EE_Registration $item
516
-     * @return string
517
-     * @throws EE_Error
518
-     * @throws InvalidArgumentException
519
-     * @throws InvalidDataTypeException
520
-     * @throws InvalidInterfaceException
521
-     * @throws ReflectionException
522
-     */
523
-    public function column_event_name(EE_Registration $item)
524
-    {
525
-        $this->_set_related_details($item);
526
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
527
-        $EVT_ID = $item->event_ID();
528
-        $event_name = $item->event_name();
529
-        $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
530
-        $event_name = wp_trim_words($event_name, 30, '...');
531
-        if ($EVT_ID) {
532
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
533
-                array('action' => 'edit', 'post' => $EVT_ID),
534
-                EVENTS_ADMIN_URL
535
-            );
536
-            $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
537
-                ? '<a class="ee-status-color-'
538
-                  . $this->_event_details['status']
539
-                  . '" href="'
540
-                  . $edit_event_url
541
-                  . '" title="'
542
-                  . esc_attr($this->_event_details['title_attr'])
543
-                  . '">'
544
-                  . $event_name
545
-                  . '</a>' : $event_name;
546
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
547
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
548
-            $actions['event_filter'] .= sprintf(
549
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
550
-                $event_name
551
-            );
552
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
553
-        } else {
554
-            $edit_event = $event_name;
555
-            $actions['event_filter'] = '';
556
-        }
557
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
558
-    }
511
+	/**
512
+	 * column_event_name
513
+	 *
514
+	 * @access public
515
+	 * @param \EE_Registration $item
516
+	 * @return string
517
+	 * @throws EE_Error
518
+	 * @throws InvalidArgumentException
519
+	 * @throws InvalidDataTypeException
520
+	 * @throws InvalidInterfaceException
521
+	 * @throws ReflectionException
522
+	 */
523
+	public function column_event_name(EE_Registration $item)
524
+	{
525
+		$this->_set_related_details($item);
526
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
527
+		$EVT_ID = $item->event_ID();
528
+		$event_name = $item->event_name();
529
+		$event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
530
+		$event_name = wp_trim_words($event_name, 30, '...');
531
+		if ($EVT_ID) {
532
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
533
+				array('action' => 'edit', 'post' => $EVT_ID),
534
+				EVENTS_ADMIN_URL
535
+			);
536
+			$edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
537
+				? '<a class="ee-status-color-'
538
+				  . $this->_event_details['status']
539
+				  . '" href="'
540
+				  . $edit_event_url
541
+				  . '" title="'
542
+				  . esc_attr($this->_event_details['title_attr'])
543
+				  . '">'
544
+				  . $event_name
545
+				  . '</a>' : $event_name;
546
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
547
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
548
+			$actions['event_filter'] .= sprintf(
549
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
550
+				$event_name
551
+			);
552
+			$actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
553
+		} else {
554
+			$edit_event = $event_name;
555
+			$actions['event_filter'] = '';
556
+		}
557
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
558
+	}
559 559
 
560 560
 
561
-    /**
562
-     * column_DTT_EVT_start
563
-     *
564
-     * @access public
565
-     * @param \EE_Registration $item
566
-     * @return string
567
-     * @throws EE_Error
568
-     * @throws InvalidArgumentException
569
-     * @throws InvalidDataTypeException
570
-     * @throws InvalidInterfaceException
571
-     * @throws ReflectionException
572
-     */
573
-    public function column_DTT_EVT_start(EE_Registration $item)
574
-    {
575
-        $datetime_strings = array();
576
-        $ticket = $item->ticket(true);
577
-        if ($ticket instanceof EE_Ticket) {
578
-            $remove_defaults = array('default_where_conditions' => 'none');
579
-            $datetimes = $ticket->datetimes($remove_defaults);
580
-            foreach ($datetimes as $datetime) {
581
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
582
-            }
583
-            return $this->generateDisplayForDatetimes($datetime_strings);
584
-        }
585
-        return __('There is no ticket on this registration', 'event_espresso');
586
-    }
561
+	/**
562
+	 * column_DTT_EVT_start
563
+	 *
564
+	 * @access public
565
+	 * @param \EE_Registration $item
566
+	 * @return string
567
+	 * @throws EE_Error
568
+	 * @throws InvalidArgumentException
569
+	 * @throws InvalidDataTypeException
570
+	 * @throws InvalidInterfaceException
571
+	 * @throws ReflectionException
572
+	 */
573
+	public function column_DTT_EVT_start(EE_Registration $item)
574
+	{
575
+		$datetime_strings = array();
576
+		$ticket = $item->ticket(true);
577
+		if ($ticket instanceof EE_Ticket) {
578
+			$remove_defaults = array('default_where_conditions' => 'none');
579
+			$datetimes = $ticket->datetimes($remove_defaults);
580
+			foreach ($datetimes as $datetime) {
581
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
582
+			}
583
+			return $this->generateDisplayForDatetimes($datetime_strings);
584
+		}
585
+		return __('There is no ticket on this registration', 'event_espresso');
586
+	}
587 587
 
588 588
 
589
-    /**
590
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
591
-     *
592
-     * @param array $datetime_strings
593
-     * @return string
594
-     */
595
-    public function generateDisplayForDateTimes(array $datetime_strings)
596
-    {
597
-        $content = '<div class="ee-registration-event-datetimes-container">';
598
-        $expand_toggle = count($datetime_strings) > 1
599
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
600
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
601
-            : '';
602
-        //get first item for initial visibility
603
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
604
-        $content .= $expand_toggle;
605
-        if ($datetime_strings) {
606
-            $content .= '<div style="clear:both"></div>';
607
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
608
-            $content .= implode("<br />", $datetime_strings);
609
-            $content .= '</div>';
610
-        }
611
-        $content .= '</div>';
612
-        return $content;
613
-    }
589
+	/**
590
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
591
+	 *
592
+	 * @param array $datetime_strings
593
+	 * @return string
594
+	 */
595
+	public function generateDisplayForDateTimes(array $datetime_strings)
596
+	{
597
+		$content = '<div class="ee-registration-event-datetimes-container">';
598
+		$expand_toggle = count($datetime_strings) > 1
599
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
600
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
601
+			: '';
602
+		//get first item for initial visibility
603
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
604
+		$content .= $expand_toggle;
605
+		if ($datetime_strings) {
606
+			$content .= '<div style="clear:both"></div>';
607
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
608
+			$content .= implode("<br />", $datetime_strings);
609
+			$content .= '</div>';
610
+		}
611
+		$content .= '</div>';
612
+		return $content;
613
+	}
614 614
 
615 615
 
616
-    /**
617
-     * column_ATT_fname
618
-     *
619
-     * @access public
620
-     * @param \EE_Registration $item
621
-     * @return string
622
-     * @throws EE_Error
623
-     * @throws InvalidArgumentException
624
-     * @throws InvalidDataTypeException
625
-     * @throws InvalidInterfaceException
626
-     * @throws ReflectionException
627
-     */
628
-    public function column_ATT_fname(EE_Registration $item)
629
-    {
630
-        $attendee = $item->attendee();
631
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
632
-            'action'  => 'view_registration',
633
-            '_REG_ID' => $item->ID(),
634
-        ), REG_ADMIN_URL);
635
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
636
-        $link = EE_Registry::instance()->CAP->current_user_can(
637
-            'ee_read_registration',
638
-            'espresso_registrations_view_registration',
639
-            $item->ID()
640
-        )
641
-            ? '<a href="'
642
-               . $edit_lnk_url
643
-               . '" title="'
644
-               . esc_attr__('View Registration Details', 'event_espresso')
645
-               . '">'
646
-               . $attendee_name
647
-               . '</a>' : $attendee_name;
648
-        $link .= $item->count() === 1
649
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
650
-        $t = $item->get_first_related('Transaction');
651
-        $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
652
-        //append group count to name
653
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
654
-        //append reg_code
655
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
656
-        //reg status text for accessibility
657
-        $link .= '<br><span class="ee-status-text-small">'
658
-                 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
659
-                 . '</span>';
660
-        //trash/restore/delete actions
661
-        $actions = array();
662
-        if ($this->_view !== 'trash'
663
-            && $payment_count === 0
664
-            && EE_Registry::instance()->CAP->current_user_can(
665
-                'ee_delete_registration',
666
-                'espresso_registrations_trash_registrations',
667
-                $item->ID()
668
-            )) {
669
-            $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
670
-                'action'  => 'trash_registrations',
671
-                '_REG_ID' => $item->ID(),
672
-            ), REG_ADMIN_URL);
673
-            $actions['trash'] = '<a href="'
674
-                                . $trash_lnk_url
675
-                                . '" title="'
676
-                                . esc_attr__('Trash Registration', 'event_espresso')
677
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
678
-        } elseif ($this->_view === 'trash') {
679
-            // restore registration link
680
-            if (EE_Registry::instance()->CAP->current_user_can(
681
-                'ee_delete_registration',
682
-                'espresso_registrations_restore_registrations',
683
-                $item->ID()
684
-            )) {
685
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
686
-                    'action'  => 'restore_registrations',
687
-                    '_REG_ID' => $item->ID(),
688
-                ), REG_ADMIN_URL);
689
-                $actions['restore'] = '<a href="'
690
-                                      . $restore_lnk_url
691
-                                      . '" title="'
692
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
693
-                                      . __('Restore', 'event_espresso') . '</a>';
694
-            }
695
-            if (EE_Registry::instance()->CAP->current_user_can(
696
-                'ee_delete_registration',
697
-                'espresso_registrations_ee_delete_registrations',
698
-                $item->ID()
699
-            )) {
700
-                $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
701
-                    'action'  => 'delete_registrations',
702
-                    '_REG_ID' => $item->ID(),
703
-                ), REG_ADMIN_URL);
704
-                $actions['delete'] = '<a href="'
705
-                                     . $delete_lnk_url
706
-                                     . '" title="'
707
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
708
-                                     . '">'
709
-                                     . __('Delete', 'event_espresso')
710
-                                     . '</a>';
711
-            }
712
-        }
713
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
714
-    }
616
+	/**
617
+	 * column_ATT_fname
618
+	 *
619
+	 * @access public
620
+	 * @param \EE_Registration $item
621
+	 * @return string
622
+	 * @throws EE_Error
623
+	 * @throws InvalidArgumentException
624
+	 * @throws InvalidDataTypeException
625
+	 * @throws InvalidInterfaceException
626
+	 * @throws ReflectionException
627
+	 */
628
+	public function column_ATT_fname(EE_Registration $item)
629
+	{
630
+		$attendee = $item->attendee();
631
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
632
+			'action'  => 'view_registration',
633
+			'_REG_ID' => $item->ID(),
634
+		), REG_ADMIN_URL);
635
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
636
+		$link = EE_Registry::instance()->CAP->current_user_can(
637
+			'ee_read_registration',
638
+			'espresso_registrations_view_registration',
639
+			$item->ID()
640
+		)
641
+			? '<a href="'
642
+			   . $edit_lnk_url
643
+			   . '" title="'
644
+			   . esc_attr__('View Registration Details', 'event_espresso')
645
+			   . '">'
646
+			   . $attendee_name
647
+			   . '</a>' : $attendee_name;
648
+		$link .= $item->count() === 1
649
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
650
+		$t = $item->get_first_related('Transaction');
651
+		$payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
652
+		//append group count to name
653
+		$link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
654
+		//append reg_code
655
+		$link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
656
+		//reg status text for accessibility
657
+		$link .= '<br><span class="ee-status-text-small">'
658
+				 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
659
+				 . '</span>';
660
+		//trash/restore/delete actions
661
+		$actions = array();
662
+		if ($this->_view !== 'trash'
663
+			&& $payment_count === 0
664
+			&& EE_Registry::instance()->CAP->current_user_can(
665
+				'ee_delete_registration',
666
+				'espresso_registrations_trash_registrations',
667
+				$item->ID()
668
+			)) {
669
+			$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
670
+				'action'  => 'trash_registrations',
671
+				'_REG_ID' => $item->ID(),
672
+			), REG_ADMIN_URL);
673
+			$actions['trash'] = '<a href="'
674
+								. $trash_lnk_url
675
+								. '" title="'
676
+								. esc_attr__('Trash Registration', 'event_espresso')
677
+								. '">' . __('Trash', 'event_espresso') . '</a>';
678
+		} elseif ($this->_view === 'trash') {
679
+			// restore registration link
680
+			if (EE_Registry::instance()->CAP->current_user_can(
681
+				'ee_delete_registration',
682
+				'espresso_registrations_restore_registrations',
683
+				$item->ID()
684
+			)) {
685
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
686
+					'action'  => 'restore_registrations',
687
+					'_REG_ID' => $item->ID(),
688
+				), REG_ADMIN_URL);
689
+				$actions['restore'] = '<a href="'
690
+									  . $restore_lnk_url
691
+									  . '" title="'
692
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
693
+									  . __('Restore', 'event_espresso') . '</a>';
694
+			}
695
+			if (EE_Registry::instance()->CAP->current_user_can(
696
+				'ee_delete_registration',
697
+				'espresso_registrations_ee_delete_registrations',
698
+				$item->ID()
699
+			)) {
700
+				$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
701
+					'action'  => 'delete_registrations',
702
+					'_REG_ID' => $item->ID(),
703
+				), REG_ADMIN_URL);
704
+				$actions['delete'] = '<a href="'
705
+									 . $delete_lnk_url
706
+									 . '" title="'
707
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
708
+									 . '">'
709
+									 . __('Delete', 'event_espresso')
710
+									 . '</a>';
711
+			}
712
+		}
713
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
714
+	}
715 715
 
716 716
 
717
-    /**
718
-     * column_ATT_email
719
-     *
720
-     * @access public
721
-     * @param \EE_Registration $item
722
-     * @return string
723
-     * @throws EE_Error
724
-     * @throws InvalidArgumentException
725
-     * @throws InvalidDataTypeException
726
-     * @throws InvalidInterfaceException
727
-     * @throws ReflectionException
728
-     */
729
-    public function column_ATT_email(EE_Registration $item)
730
-    {
731
-        $attendee = $item->get_first_related('Attendee');
732
-        return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
733
-            : $attendee->email();
734
-    }
717
+	/**
718
+	 * column_ATT_email
719
+	 *
720
+	 * @access public
721
+	 * @param \EE_Registration $item
722
+	 * @return string
723
+	 * @throws EE_Error
724
+	 * @throws InvalidArgumentException
725
+	 * @throws InvalidDataTypeException
726
+	 * @throws InvalidInterfaceException
727
+	 * @throws ReflectionException
728
+	 */
729
+	public function column_ATT_email(EE_Registration $item)
730
+	{
731
+		$attendee = $item->get_first_related('Attendee');
732
+		return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
733
+			: $attendee->email();
734
+	}
735 735
 
736 736
 
737
-    /**
738
-     * column__REG_count
739
-     *
740
-     * @access public
741
-     * @param \EE_Registration $item
742
-     * @return string
743
-     */
744
-    public function column__REG_count(EE_Registration $item)
745
-    {
746
-        return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
747
-    }
737
+	/**
738
+	 * column__REG_count
739
+	 *
740
+	 * @access public
741
+	 * @param \EE_Registration $item
742
+	 * @return string
743
+	 */
744
+	public function column__REG_count(EE_Registration $item)
745
+	{
746
+		return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
747
+	}
748 748
 
749 749
 
750
-    /**
751
-     * column_PRC_amount
752
-     *
753
-     * @access public
754
-     * @param \EE_Registration $item
755
-     * @return string
756
-     * @throws EE_Error
757
-     */
758
-    public function column_PRC_amount(EE_Registration $item)
759
-    {
760
-        $ticket = $item->ticket();
761
-        $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
762
-                                                                              . $ticket->name()
763
-                                                                              . '</span><br />' : '';
764
-        if ($item->final_price() > 0) {
765
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
766
-        } else {
767
-            // free event
768
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
769
-                        . __('free', 'event_espresso')
770
-                        . '</span>';
771
-        }
772
-        return $content;
773
-    }
750
+	/**
751
+	 * column_PRC_amount
752
+	 *
753
+	 * @access public
754
+	 * @param \EE_Registration $item
755
+	 * @return string
756
+	 * @throws EE_Error
757
+	 */
758
+	public function column_PRC_amount(EE_Registration $item)
759
+	{
760
+		$ticket = $item->ticket();
761
+		$content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
762
+																			  . $ticket->name()
763
+																			  . '</span><br />' : '';
764
+		if ($item->final_price() > 0) {
765
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
766
+		} else {
767
+			// free event
768
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
769
+						. __('free', 'event_espresso')
770
+						. '</span>';
771
+		}
772
+		return $content;
773
+	}
774 774
 
775 775
 
776
-    /**
777
-     * column__REG_final_price
778
-     *
779
-     * @access public
780
-     * @param \EE_Registration $item
781
-     * @return string
782
-     * @throws EE_Error
783
-     */
784
-    public function column__REG_final_price(EE_Registration $item)
785
-    {
786
-        $ticket = $item->ticket();
787
-        $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
788
-            ? ''
789
-            : '<span class="TKT_name">'
790
-              . $ticket->name()
791
-              . '</span><br />';
792
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
793
-        return $content;
794
-    }
776
+	/**
777
+	 * column__REG_final_price
778
+	 *
779
+	 * @access public
780
+	 * @param \EE_Registration $item
781
+	 * @return string
782
+	 * @throws EE_Error
783
+	 */
784
+	public function column__REG_final_price(EE_Registration $item)
785
+	{
786
+		$ticket = $item->ticket();
787
+		$content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
788
+			? ''
789
+			: '<span class="TKT_name">'
790
+			  . $ticket->name()
791
+			  . '</span><br />';
792
+		$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
793
+		return $content;
794
+	}
795 795
 
796 796
 
797
-    /**
798
-     * column__REG_paid
799
-     *
800
-     * @access public
801
-     * @param \EE_Registration $item
802
-     * @return string
803
-     * @throws EE_Error
804
-     */
805
-    public function column__REG_paid(EE_Registration $item)
806
-    {
807
-        $payment_method = $item->payment_method();
808
-        $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
809
-            : __('Unknown', 'event_espresso');
810
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
811
-        if ($item->paid() > 0) {
812
-            $content .= '<br><span class="ee-status-text-small">'
813
-                        . sprintf(
814
-                            __('...via %s', 'event_espresso'),
815
-                            $payment_method_name
816
-                        )
817
-                        . '</span>';
818
-        }
819
-        return $content;
820
-    }
797
+	/**
798
+	 * column__REG_paid
799
+	 *
800
+	 * @access public
801
+	 * @param \EE_Registration $item
802
+	 * @return string
803
+	 * @throws EE_Error
804
+	 */
805
+	public function column__REG_paid(EE_Registration $item)
806
+	{
807
+		$payment_method = $item->payment_method();
808
+		$payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
809
+			: __('Unknown', 'event_espresso');
810
+		$content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
811
+		if ($item->paid() > 0) {
812
+			$content .= '<br><span class="ee-status-text-small">'
813
+						. sprintf(
814
+							__('...via %s', 'event_espresso'),
815
+							$payment_method_name
816
+						)
817
+						. '</span>';
818
+		}
819
+		return $content;
820
+	}
821 821
 
822 822
 
823
-    /**
824
-     * column_TXN_total
825
-     *
826
-     * @access public
827
-     * @param \EE_Registration $item
828
-     * @return string
829
-     * @throws EE_Error
830
-     * @throws EntityNotFoundException
831
-     * @throws InvalidArgumentException
832
-     * @throws InvalidDataTypeException
833
-     * @throws InvalidInterfaceException
834
-     */
835
-    public function column_TXN_total(EE_Registration $item)
836
-    {
837
-        if ($item->transaction()) {
838
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
839
-                'action' => 'view_transaction',
840
-                'TXN_ID' => $item->transaction_ID(),
841
-            ), TXN_ADMIN_URL);
842
-            return EE_Registry::instance()->CAP->current_user_can(
843
-                'ee_read_transaction',
844
-                'espresso_transactions_view_transaction',
845
-                $item->transaction_ID()
846
-            )
847
-                ? '<span class="reg-pad-rght"><a class="status-'
848
-                  . $item->transaction()->status_ID()
849
-                  . '" href="'
850
-                  . $view_txn_lnk_url
851
-                  . '"  title="'
852
-                  . esc_attr__('View Transaction', 'event_espresso')
853
-                  . '">'
854
-                  . $item->transaction()->pretty_total()
855
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
856
-        } else {
857
-            return __("None", "event_espresso");
858
-        }
859
-    }
823
+	/**
824
+	 * column_TXN_total
825
+	 *
826
+	 * @access public
827
+	 * @param \EE_Registration $item
828
+	 * @return string
829
+	 * @throws EE_Error
830
+	 * @throws EntityNotFoundException
831
+	 * @throws InvalidArgumentException
832
+	 * @throws InvalidDataTypeException
833
+	 * @throws InvalidInterfaceException
834
+	 */
835
+	public function column_TXN_total(EE_Registration $item)
836
+	{
837
+		if ($item->transaction()) {
838
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
839
+				'action' => 'view_transaction',
840
+				'TXN_ID' => $item->transaction_ID(),
841
+			), TXN_ADMIN_URL);
842
+			return EE_Registry::instance()->CAP->current_user_can(
843
+				'ee_read_transaction',
844
+				'espresso_transactions_view_transaction',
845
+				$item->transaction_ID()
846
+			)
847
+				? '<span class="reg-pad-rght"><a class="status-'
848
+				  . $item->transaction()->status_ID()
849
+				  . '" href="'
850
+				  . $view_txn_lnk_url
851
+				  . '"  title="'
852
+				  . esc_attr__('View Transaction', 'event_espresso')
853
+				  . '">'
854
+				  . $item->transaction()->pretty_total()
855
+				  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
856
+		} else {
857
+			return __("None", "event_espresso");
858
+		}
859
+	}
860 860
 
861 861
 
862
-    /**
863
-     * column_TXN_paid
864
-     *
865
-     * @access public
866
-     * @param \EE_Registration $item
867
-     * @return string
868
-     * @throws EE_Error
869
-     * @throws EntityNotFoundException
870
-     * @throws InvalidArgumentException
871
-     * @throws InvalidDataTypeException
872
-     * @throws InvalidInterfaceException
873
-     */
874
-    public function column_TXN_paid(EE_Registration $item)
875
-    {
876
-        if ($item->count() === 1) {
877
-            $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
878
-            if ($transaction->paid() >= $transaction->total()) {
879
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
880
-            } else {
881
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
882
-                    'action' => 'view_transaction',
883
-                    'TXN_ID' => $item->transaction_ID(),
884
-                ), TXN_ADMIN_URL);
885
-                return EE_Registry::instance()->CAP->current_user_can(
886
-                    'ee_read_transaction',
887
-                    'espresso_transactions_view_transaction',
888
-                    $item->transaction_ID()
889
-                )
890
-                    ? '<span class="reg-pad-rght"><a class="status-'
891
-                      . $transaction->status_ID()
892
-                      . '" href="'
893
-                      . $view_txn_lnk_url
894
-                      . '"  title="'
895
-                      . esc_attr__('View Transaction', 'event_espresso')
896
-                      . '">'
897
-                      . $item->transaction()->pretty_paid()
898
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
899
-            }
900
-        }
901
-        return '&nbsp;';
902
-    }
862
+	/**
863
+	 * column_TXN_paid
864
+	 *
865
+	 * @access public
866
+	 * @param \EE_Registration $item
867
+	 * @return string
868
+	 * @throws EE_Error
869
+	 * @throws EntityNotFoundException
870
+	 * @throws InvalidArgumentException
871
+	 * @throws InvalidDataTypeException
872
+	 * @throws InvalidInterfaceException
873
+	 */
874
+	public function column_TXN_paid(EE_Registration $item)
875
+	{
876
+		if ($item->count() === 1) {
877
+			$transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
878
+			if ($transaction->paid() >= $transaction->total()) {
879
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
880
+			} else {
881
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
882
+					'action' => 'view_transaction',
883
+					'TXN_ID' => $item->transaction_ID(),
884
+				), TXN_ADMIN_URL);
885
+				return EE_Registry::instance()->CAP->current_user_can(
886
+					'ee_read_transaction',
887
+					'espresso_transactions_view_transaction',
888
+					$item->transaction_ID()
889
+				)
890
+					? '<span class="reg-pad-rght"><a class="status-'
891
+					  . $transaction->status_ID()
892
+					  . '" href="'
893
+					  . $view_txn_lnk_url
894
+					  . '"  title="'
895
+					  . esc_attr__('View Transaction', 'event_espresso')
896
+					  . '">'
897
+					  . $item->transaction()->pretty_paid()
898
+					  . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
899
+			}
900
+		}
901
+		return '&nbsp;';
902
+	}
903 903
 
904 904
 
905
-    /**
906
-     * column_actions
907
-     *
908
-     * @access public
909
-     * @param \EE_Registration $item
910
-     * @return string
911
-     * @throws EE_Error
912
-     * @throws InvalidArgumentException
913
-     * @throws InvalidDataTypeException
914
-     * @throws InvalidInterfaceException
915
-     * @throws ReflectionException
916
-     */
917
-    public function column_actions(EE_Registration $item)
918
-    {
919
-        $actions = array();
920
-        $attendee = $item->attendee();
921
-        $this->_set_related_details($item);
922
-        //Build row actions
923
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
924
-            'action'  => 'view_registration',
925
-            '_REG_ID' => $item->ID(),
926
-        ), REG_ADMIN_URL);
927
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
928
-            'action' => 'edit_attendee',
929
-            'post'   => $item->attendee_ID(),
930
-        ), REG_ADMIN_URL);
931
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
932
-        //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
933
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
934
-            'action'  => 'resend_registration',
935
-            '_REG_ID' => $item->ID(),
936
-        ), REG_ADMIN_URL, true);
937
-        //Build row actions
938
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
939
-            'ee_read_registration',
940
-            'espresso_registrations_view_registration',
941
-            $item->ID()
942
-        ) ? '<li><a href="'
943
-            . $view_lnk_url
944
-            . '" title="'
945
-            . esc_attr__('View Registration Details', 'event_espresso')
946
-            . '" class="tiny-text">
905
+	/**
906
+	 * column_actions
907
+	 *
908
+	 * @access public
909
+	 * @param \EE_Registration $item
910
+	 * @return string
911
+	 * @throws EE_Error
912
+	 * @throws InvalidArgumentException
913
+	 * @throws InvalidDataTypeException
914
+	 * @throws InvalidInterfaceException
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function column_actions(EE_Registration $item)
918
+	{
919
+		$actions = array();
920
+		$attendee = $item->attendee();
921
+		$this->_set_related_details($item);
922
+		//Build row actions
923
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
924
+			'action'  => 'view_registration',
925
+			'_REG_ID' => $item->ID(),
926
+		), REG_ADMIN_URL);
927
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
928
+			'action' => 'edit_attendee',
929
+			'post'   => $item->attendee_ID(),
930
+		), REG_ADMIN_URL);
931
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
932
+		//$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
933
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
934
+			'action'  => 'resend_registration',
935
+			'_REG_ID' => $item->ID(),
936
+		), REG_ADMIN_URL, true);
937
+		//Build row actions
938
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
939
+			'ee_read_registration',
940
+			'espresso_registrations_view_registration',
941
+			$item->ID()
942
+		) ? '<li><a href="'
943
+			. $view_lnk_url
944
+			. '" title="'
945
+			. esc_attr__('View Registration Details', 'event_espresso')
946
+			. '" class="tiny-text">
947 947
 				<div class="dashicons dashicons-clipboard"></div>
948 948
 			</a>
949 949
 			</li>'
950
-            : '';
951
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
952
-            'ee_edit_contacts',
953
-            'espresso_registrations_edit_attendee'
954
-        )
955
-                               && $attendee instanceof EE_Attendee
956
-            ? '
950
+			: '';
951
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
952
+			'ee_edit_contacts',
953
+			'espresso_registrations_edit_attendee'
954
+		)
955
+							   && $attendee instanceof EE_Attendee
956
+			? '
957 957
 			<li>
958 958
 			<a href="' . $edit_lnk_url . '" title="'
959
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
959
+			  . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
960 960
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
961 961
 			</a>
962 962
 			</li>' : '';
963
-        $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
964
-                                     && EE_Registry::instance()->CAP->current_user_can(
965
-                                         'ee_send_message',
966
-                                         'espresso_registrations_resend_registration',
967
-                                         $item->ID()
968
-        )
969
-            ? '
963
+		$actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
964
+									 && EE_Registry::instance()->CAP->current_user_can(
965
+										 'ee_send_message',
966
+										 'espresso_registrations_resend_registration',
967
+										 $item->ID()
968
+		)
969
+			? '
970 970
 			<li>
971 971
 			<a href="'
972
-                 . $resend_reg_lnk_url
973
-                 . '" title="'
974
-                 . esc_attr__('Resend Registration Details', 'event_espresso')
975
-                 . '" class="tiny-text">
972
+				 . $resend_reg_lnk_url
973
+				 . '" title="'
974
+				 . esc_attr__('Resend Registration Details', 'event_espresso')
975
+				 . '" class="tiny-text">
976 976
 				<div class="dashicons dashicons-email-alt"></div>
977 977
 			</a>
978 978
 			</li>' : '';
979
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
980
-        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
981
-            'action' => 'view_transaction',
982
-            'TXN_ID' => $this->_transaction_details['id'],
983
-        ), TXN_ADMIN_URL);
984
-        $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
-            'ee_read_transaction',
986
-            'espresso_transactions_view_transaction',
987
-            $this->_transaction_details['id']
988
-        )
989
-            ? '
979
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
980
+		$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
981
+			'action' => 'view_transaction',
982
+			'TXN_ID' => $this->_transaction_details['id'],
983
+		), TXN_ADMIN_URL);
984
+		$actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
+			'ee_read_transaction',
986
+			'espresso_transactions_view_transaction',
987
+			$this->_transaction_details['id']
988
+		)
989
+			? '
990 990
 			<li>
991 991
 			<a class="ee-status-color-'
992
-               . $this->_transaction_details['status']
993
-               . ' tiny-text" href="'
994
-               . $view_txn_lnk_url
995
-               . '"  title="'
996
-               . $this->_transaction_details['title_attr']
997
-               . '">
992
+			   . $this->_transaction_details['status']
993
+			   . ' tiny-text" href="'
994
+			   . $view_txn_lnk_url
995
+			   . '"  title="'
996
+			   . $this->_transaction_details['title_attr']
997
+			   . '">
998 998
 				<div class="dashicons dashicons-cart"></div>
999 999
 			</a>
1000 1000
 			</li>' : '';
1001
-        //invoice link
1002
-        $actions['dl_invoice_lnk'] = '';
1003
-        $dl_invoice_lnk_url = $item->invoice_url();
1004
-        //only show invoice link if message type is active.
1005
-        if ($attendee instanceof EE_Attendee
1006
-            && $item->is_primary_registrant()
1007
-            && EEH_MSG_Template::is_mt_active('invoice')
1008
-        ) {
1009
-            $actions['dl_invoice_lnk'] = '
1001
+		//invoice link
1002
+		$actions['dl_invoice_lnk'] = '';
1003
+		$dl_invoice_lnk_url = $item->invoice_url();
1004
+		//only show invoice link if message type is active.
1005
+		if ($attendee instanceof EE_Attendee
1006
+			&& $item->is_primary_registrant()
1007
+			&& EEH_MSG_Template::is_mt_active('invoice')
1008
+		) {
1009
+			$actions['dl_invoice_lnk'] = '
1010 1010
 		<li>
1011 1011
 			<a title="'
1012
-                 . esc_attr__('View Transaction Invoice', 'event_espresso')
1013
-                 . '" target="_blank" href="'
1014
-                 . $dl_invoice_lnk_url
1015
-                 . '" class="tiny-text">
1012
+				 . esc_attr__('View Transaction Invoice', 'event_espresso')
1013
+				 . '" target="_blank" href="'
1014
+				 . $dl_invoice_lnk_url
1015
+				 . '" class="tiny-text">
1016 1016
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1017 1017
 			</a>
1018 1018
 		</li>';
1019
-        }
1020
-        $actions['filtered_messages_link'] = '';
1021
-        //message list table link (filtered by REG_ID
1022
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1023
-            $actions['filtered_messages_link'] = '<li>'
1024
-                     . EEH_MSG_Template::get_message_action_link(
1025
-                         'see_notifications_for',
1026
-                         null,
1027
-                         array('_REG_ID' => $item->ID())
1028
-                     ) . '</li>';
1029
-        }
1030
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1031
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1032
-    }
1019
+		}
1020
+		$actions['filtered_messages_link'] = '';
1021
+		//message list table link (filtered by REG_ID
1022
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1023
+			$actions['filtered_messages_link'] = '<li>'
1024
+					 . EEH_MSG_Template::get_message_action_link(
1025
+						 'see_notifications_for',
1026
+						 null,
1027
+						 array('_REG_ID' => $item->ID())
1028
+					 ) . '</li>';
1029
+		}
1030
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1031
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1032
+	}
1033 1033
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidDataTypeException;
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 
5
-if (! defined('EVENT_ESPRESSO_VERSION')) {
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6 6
     exit('No direct script access allowed');
7 7
 }
8 8
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function __construct(Registrations_Admin_Page $admin_page)
59 59
     {
60
-        if (! empty($_GET['event_id'])) {
60
+        if ( ! empty($_GET['event_id'])) {
61 61
             $extra_query_args = array();
62 62
             foreach ($admin_page->get_views() as $key => $view_details) {
63 63
                 $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         );
158 158
         $this->_primary_column = '_REG_ID';
159 159
         $this->_sortable_columns = array(
160
-            '_REG_date'     => array('_REG_date' => true),   //true means its already sorted
160
+            '_REG_date'     => array('_REG_date' => true), //true means its already sorted
161 161
             /**
162 162
              * Allows users to change the default sort if they wish.
163 163
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     {
190 190
         $class = parent::_get_row_class($item);
191 191
         //add status class
192
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
192
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
193 193
         if ($this->_has_checkbox_column) {
194 194
             $class .= ' has-checkbox-column';
195 195
         }
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
         //setup date query.
355 355
         $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
356 356
             'REG_date',
357
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
357
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
358 358
             'Y-m-d H:i:s'
359 359
         );
360 360
         $end_string = EEM_Registration::instance()->convert_datetime_for_query(
361 361
             'REG_date',
362
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
362
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
363 363
             'Y-m-d H:i:s'
364 364
         );
365 365
         $_where['REG_date'] = array(
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
             array(
397 397
                 EEM_Registration::instance()->convert_datetime_for_query(
398 398
                     'REG_date',
399
-                    $current_date . $time_start,
399
+                    $current_date.$time_start,
400 400
                     'Y-m-d H:i:s'
401 401
                 ),
402 402
                 EEM_Registration::instance()->convert_datetime_for_query(
403 403
                     'REG_date',
404
-                    $current_date . $time_end,
404
+                    $current_date.$time_end,
405 405
                     'Y-m-d H:i:s'
406 406
                 ),
407 407
             ),
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
         $content .= '<div class="show-on-mobile-view-only">';
462 462
         $content .= '<br>';
463 463
         $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
464
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
464
+        $content .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
465
+        $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
466 466
         $content .= '</div>';
467 467
         return $content;
468 468
     }
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
                   . $event_name
545 545
                   . '</a>' : $event_name;
546 546
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
547
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
547
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
548 548
             $actions['event_filter'] .= sprintf(
549 549
                 esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
550 550
                 $event_name
551 551
             );
552
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
552
+            $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>';
553 553
         } else {
554 554
             $edit_event = $event_name;
555 555
             $actions['event_filter'] = '';
@@ -596,11 +596,11 @@  discard block
 block discarded – undo
596 596
     {
597 597
         $content = '<div class="ee-registration-event-datetimes-container">';
598 598
         $expand_toggle = count($datetime_strings) > 1
599
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
599
+            ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso')
600 600
               . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
601 601
             : '';
602 602
         //get first item for initial visibility
603
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
603
+        $content .= '<div class="left">'.array_shift($datetime_strings).'</div>';
604 604
         $content .= $expand_toggle;
605 605
         if ($datetime_strings) {
606 606
             $content .= '<div style="clear:both"></div>';
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
         $t = $item->get_first_related('Transaction');
651 651
         $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
652 652
         //append group count to name
653
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
653
+        $link .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
654 654
         //append reg_code
655
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
655
+        $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
656 656
         //reg status text for accessibility
657 657
         $link .= '<br><span class="ee-status-text-small">'
658 658
                  . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
                                 . $trash_lnk_url
675 675
                                 . '" title="'
676 676
                                 . esc_attr__('Trash Registration', 'event_espresso')
677
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
677
+                                . '">'.__('Trash', 'event_espresso').'</a>';
678 678
         } elseif ($this->_view === 'trash') {
679 679
             // restore registration link
680 680
             if (EE_Registry::instance()->CAP->current_user_can(
@@ -689,8 +689,8 @@  discard block
 block discarded – undo
689 689
                 $actions['restore'] = '<a href="'
690 690
                                       . $restore_lnk_url
691 691
                                       . '" title="'
692
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
693
-                                      . __('Restore', 'event_espresso') . '</a>';
692
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
693
+                                      . __('Restore', 'event_espresso').'</a>';
694 694
             }
695 695
             if (EE_Registry::instance()->CAP->current_user_can(
696 696
                 'ee_delete_registration',
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
                                                                               . $ticket->name()
763 763
                                                                               . '</span><br />' : '';
764 764
         if ($item->final_price() > 0) {
765
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
765
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
766 766
         } else {
767 767
             // free event
768 768
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             : '<span class="TKT_name">'
790 790
               . $ticket->name()
791 791
               . '</span><br />';
792
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
792
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
793 793
         return $content;
794 794
     }
795 795
 
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
         $payment_method = $item->payment_method();
808 808
         $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
809 809
             : __('Unknown', 'event_espresso');
810
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
810
+        $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
811 811
         if ($item->paid() > 0) {
812 812
             $content .= '<br><span class="ee-status-text-small">'
813 813
                         . sprintf(
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
                   . esc_attr__('View Transaction', 'event_espresso')
853 853
                   . '">'
854 854
                   . $item->transaction()->pretty_total()
855
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
855
+                  . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
856 856
         } else {
857 857
             return __("None", "event_espresso");
858 858
         }
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
                       . esc_attr__('View Transaction', 'event_espresso')
896 896
                       . '">'
897 897
                       . $item->transaction()->pretty_paid()
898
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
898
+                      . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
899 899
             }
900 900
         }
901 901
         return '&nbsp;';
@@ -955,8 +955,8 @@  discard block
 block discarded – undo
955 955
                                && $attendee instanceof EE_Attendee
956 956
             ? '
957 957
 			<li>
958
-			<a href="' . $edit_lnk_url . '" title="'
959
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
958
+			<a href="' . $edit_lnk_url.'" title="'
959
+              . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text">
960 960
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
961 961
 			</a>
962 962
 			</li>' : '';
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
                          'see_notifications_for',
1026 1026
                          null,
1027 1027
                          array('_REG_ID' => $item->ID())
1028
-                     ) . '</li>';
1028
+                     ).'</li>';
1029 1029
         }
1030 1030
         $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1031 1031
         return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 1 patch
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -8,644 +8,644 @@
 block discarded – undo
8 8
 class EE_Email_messenger extends EE_messenger
9 9
 {
10 10
 
11
-    /**
12
-     * To field for email
13
-     * @var string
14
-     */
15
-    protected $_to = '';
16
-
17
-
18
-    /**
19
-     * CC field for email.
20
-     * @var string
21
-     */
22
-    protected $_cc = '';
23
-
24
-    /**
25
-     * From field for email
26
-     * @var string
27
-     */
28
-    protected $_from = '';
29
-
30
-
31
-    /**
32
-     * Subject field for email
33
-     * @var string
34
-     */
35
-    protected $_subject = '';
36
-
37
-
38
-    /**
39
-     * Content field for email
40
-     * @var string
41
-     */
42
-    protected $_content = '';
43
-
44
-
45
-    /**
46
-     * constructor
47
-     *
48
-     * @access public
49
-     */
50
-    public function __construct()
51
-    {
52
-        //set name and description properties
53
-        $this->name                = 'email';
54
-        $this->description         = sprintf(
55
-            esc_html__(
56
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
57
-                'event_espresso'
58
-            ),
59
-            '<code>wp_mail</code>'
60
-        );
61
-        $this->label               = array(
62
-            'singular' => esc_html__('email', 'event_espresso'),
63
-            'plural'   => esc_html__('emails', 'event_espresso'),
64
-        );
65
-        $this->activate_on_install = true;
66
-
67
-        //we're using defaults so let's call parent constructor that will take care of setting up all the other
68
-        // properties
69
-        parent::__construct();
70
-    }
71
-
72
-
73
-    /**
74
-     * see abstract declaration in parent class for details.
75
-     */
76
-    protected function _set_admin_pages()
77
-    {
78
-        $this->admin_registered_pages = array(
79
-            'events_edit' => true,
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * see abstract declaration in parent class for details
86
-     */
87
-    protected function _set_valid_shortcodes()
88
-    {
89
-        //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
90
-        // message type.
91
-        $this->_valid_shortcodes = array(
92
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
94
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
95
-        );
96
-    }
97
-
98
-
99
-    /**
100
-     * see abstract declaration in parent class for details
101
-     *
102
-     * @access protected
103
-     * @return void
104
-     */
105
-    protected function _set_validator_config()
106
-    {
107
-        $valid_shortcodes = $this->get_valid_shortcodes();
108
-
109
-        $this->_validator_config = array(
110
-            'to'            => array(
111
-                'shortcodes' => $valid_shortcodes['to'],
112
-                'type'       => 'email',
113
-            ),
114
-            'cc' => array(
115
-                'shortcodes' => $valid_shortcodes['to'],
116
-                'type' => 'email',
117
-            ),
118
-            'from'          => array(
119
-                'shortcodes' => $valid_shortcodes['from'],
120
-                'type'       => 'email',
121
-            ),
122
-            'subject'       => array(
123
-                'shortcodes' => array(
124
-                    'organization',
125
-                    'primary_registration_details',
126
-                    'event_author',
127
-                    'primary_registration_details',
128
-                    'recipient_details',
129
-                ),
130
-            ),
131
-            'content'       => array(
132
-                'shortcodes' => array(
133
-                    'event_list',
134
-                    'attendee_list',
135
-                    'ticket_list',
136
-                    'organization',
137
-                    'primary_registration_details',
138
-                    'primary_registration_list',
139
-                    'event_author',
140
-                    'recipient_details',
141
-                    'recipient_list',
142
-                    'transaction',
143
-                    'messenger',
144
-                ),
145
-            ),
146
-            'attendee_list' => array(
147
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
148
-                'required'   => array('[ATTENDEE_LIST]'),
149
-            ),
150
-            'event_list'    => array(
151
-                'shortcodes' => array(
152
-                    'event',
153
-                    'attendee_list',
154
-                    'ticket_list',
155
-                    'venue',
156
-                    'datetime_list',
157
-                    'attendee',
158
-                    'primary_registration_details',
159
-                    'primary_registration_list',
160
-                    'event_author',
161
-                    'recipient_details',
162
-                    'recipient_list',
163
-                ),
164
-                'required'   => array('[EVENT_LIST]'),
165
-            ),
166
-            'ticket_list'   => array(
167
-                'shortcodes' => array(
168
-                    'event_list',
169
-                    'attendee_list',
170
-                    'ticket',
171
-                    'datetime_list',
172
-                    'primary_registration_details',
173
-                    'recipient_details',
174
-                ),
175
-                'required'   => array('[TICKET_LIST]'),
176
-            ),
177
-            'datetime_list' => array(
178
-                'shortcodes' => array('datetime'),
179
-                'required'   => array('[DATETIME_LIST]'),
180
-            ),
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * @see   parent EE_messenger class for docs
187
-     * @since 4.5.0
188
-     */
189
-    public function do_secondary_messenger_hooks($sending_messenger_name)
190
-    {
191
-        if ($sending_messenger_name = 'html') {
192
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
193
-        }
194
-    }
195
-
196
-
197
-    public function add_email_css(
198
-        $variation_path,
199
-        $messenger,
200
-        $message_type,
201
-        $type,
202
-        $variation,
203
-        $file_extension,
204
-        $url,
205
-        EE_Messages_Template_Pack $template_pack
206
-    ) {
207
-        //prevent recursion on this callback.
208
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
209
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
210
-
211
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
212
-        return $variation;
213
-    }
214
-
215
-
216
-    /**
217
-     * See parent for details
218
-     *
219
-     * @access protected
220
-     * @return void
221
-     */
222
-    protected function _set_test_settings_fields()
223
-    {
224
-        $this->_test_settings_fields = array(
225
-            'to'      => array(
226
-                'input'      => 'text',
227
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
228
-                'type'       => 'email',
229
-                'required'   => true,
230
-                'validation' => true,
231
-                'css_class'  => 'large-text',
232
-                'format'     => '%s',
233
-                'default'    => get_bloginfo('admin_email'),
234
-            ),
235
-            'subject' => array(
236
-                'input'      => 'hidden',
237
-                'label'      => '',
238
-                'type'       => 'string',
239
-                'required'   => false,
240
-                'validation' => false,
241
-                'format'     => '%s',
242
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
243
-                'default'    => '',
244
-                'css_class'  => '',
245
-            ),
246
-        );
247
-    }
248
-
249
-
250
-    /**
251
-     * _set_template_fields
252
-     * This sets up the fields that a messenger requires for the message to go out.
253
-     *
254
-     * @access  protected
255
-     * @return void
256
-     */
257
-    protected function _set_template_fields()
258
-    {
259
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
260
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
261
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
262
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
263
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
264
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
265
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
266
-        // will not be displayed/parsed.
267
-        $this->_template_fields = array(
268
-            'to'      => array(
269
-                'input'      => 'text',
270
-                'label'      => esc_html_x(
271
-                    'To',
272
-                    'Label for the "To" field for email addresses',
273
-                    'event_espresso'
274
-                ),
275
-                'type'       => 'string',
276
-                'required'   => true,
277
-                'validation' => true,
278
-                'css_class'  => 'large-text',
279
-                'format'     => '%s',
280
-            ),
281
-            'cc'      => array(
282
-                'input'      => 'text',
283
-                'label'      => esc_html_x(
284
-                    'CC',
285
-                    'Label for the "Carbon Copy" field used for additional email addresses',
286
-                    'event_espresso'
287
-                ),
288
-                'type'       => 'string',
289
-                'required'   => false,
290
-                'validation' => true,
291
-                'css_class'  => 'large-text',
292
-                'format'     => '%s',
293
-            ),
294
-            'from'    => array(
295
-                'input'      => 'text',
296
-                'label'      => esc_html_x(
297
-                    'From',
298
-                    'Label for the "From" field for email addresses.',
299
-                    'event_espresso'
300
-                ),
301
-                'type'       => 'string',
302
-                'required'   => true,
303
-                'validation' => true,
304
-                'css_class'  => 'large-text',
305
-                'format'     => '%s',
306
-            ),
307
-            'subject' => array(
308
-                'input'      => 'text',
309
-                'label'      => esc_html_x(
310
-                    'Subject',
311
-                    'Label for the "Subject" field (short description of contents) for emails.',
312
-                    'event_espresso'
313
-                ),
314
-                'type'       => 'string',
315
-                'required'   => true,
316
-                'validation' => true,
317
-                'css_class'  => 'large-text',
318
-                'format'     => '%s',
319
-            ),
320
-            'content' => '',
321
-            //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
322
-            'extra'   => array(
323
-                'content' => array(
324
-                    'main'          => array(
325
-                        'input'      => 'wp_editor',
326
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
327
-                        'type'       => 'string',
328
-                        'required'   => true,
329
-                        'validation' => true,
330
-                        'format'     => '%s',
331
-                        'rows'       => '15',
332
-                    ),
333
-                    'event_list'    => array(
334
-                        'input'               => 'wp_editor',
335
-                        'label'               => '[EVENT_LIST]',
336
-                        'type'                => 'string',
337
-                        'required'            => true,
338
-                        'validation'          => true,
339
-                        'format'              => '%s',
340
-                        'rows'                => '15',
341
-                        'shortcodes_required' => array('[EVENT_LIST]'),
342
-                    ),
343
-                    'attendee_list' => array(
344
-                        'input'               => 'textarea',
345
-                        'label'               => '[ATTENDEE_LIST]',
346
-                        'type'                => 'string',
347
-                        'required'            => true,
348
-                        'validation'          => true,
349
-                        'format'              => '%s',
350
-                        'css_class'           => 'large-text',
351
-                        'rows'                => '5',
352
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
353
-                    ),
354
-                    'ticket_list'   => array(
355
-                        'input'               => 'textarea',
356
-                        'label'               => '[TICKET_LIST]',
357
-                        'type'                => 'string',
358
-                        'required'            => true,
359
-                        'validation'          => true,
360
-                        'format'              => '%s',
361
-                        'css_class'           => 'large-text',
362
-                        'rows'                => '10',
363
-                        'shortcodes_required' => array('[TICKET_LIST]'),
364
-                    ),
365
-                    'datetime_list' => array(
366
-                        'input'               => 'textarea',
367
-                        'label'               => '[DATETIME_LIST]',
368
-                        'type'                => 'string',
369
-                        'required'            => true,
370
-                        'validation'          => true,
371
-                        'format'              => '%s',
372
-                        'css_class'           => 'large-text',
373
-                        'rows'                => '10',
374
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
375
-                    ),
376
-                ),
377
-            ),
378
-        );
379
-    }
380
-
381
-
382
-    /**
383
-     * See definition of this class in parent
384
-     */
385
-    protected function _set_default_message_types()
386
-    {
387
-        $this->_default_message_types = array(
388
-            'payment',
389
-            'payment_refund',
390
-            'registration',
391
-            'not_approved_registration',
392
-            'pending_approval',
393
-        );
394
-    }
395
-
396
-
397
-    /**
398
-     * @see   definition of this class in parent
399
-     * @since 4.5.0
400
-     */
401
-    protected function _set_valid_message_types()
402
-    {
403
-        $this->_valid_message_types = array(
404
-            'payment',
405
-            'registration',
406
-            'not_approved_registration',
407
-            'declined_registration',
408
-            'cancelled_registration',
409
-            'pending_approval',
410
-            'registration_summary',
411
-            'payment_reminder',
412
-            'payment_declined',
413
-            'payment_refund',
414
-        );
415
-    }
416
-
417
-
418
-    /**
419
-     * setting up admin_settings_fields for messenger.
420
-     */
421
-    protected function _set_admin_settings_fields()
422
-    {
423
-    }
424
-
425
-    /**
426
-     * We just deliver the messages don't kill us!!
427
-     *
428
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
429
-     *              present.
430
-     * @throws EE_Error
431
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
432
-     */
433
-    protected function _send_message()
434
-    {
435
-        $success = wp_mail(
436
-            $this->_to,
437
-            //some old values for subject may be expecting HTML entities to be decoded in the subject
438
-            //and subjects aren't interpreted as HTML, so there should be no HTML in them
439
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
440
-            $this->_body(),
441
-            $this->_headers()
442
-        );
443
-        if (! $success) {
444
-            EE_Error::add_error(
445
-                sprintf(
446
-                    esc_html__(
447
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
448
-                        'event_espresso'
449
-                    ),
450
-                    $this->_to,
451
-                    $this->_from,
452
-                    '<br />'
453
-                ),
454
-                __FILE__,
455
-                __FUNCTION__,
456
-                __LINE__
457
-            );
458
-        }
459
-        return $success;
460
-    }
461
-
462
-
463
-    /**
464
-     * see parent for definition
465
-     *
466
-     * @return string html body of the message content and the related css.
467
-     * @throws EE_Error
468
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
469
-     */
470
-    protected function _preview()
471
-    {
472
-        return $this->_body(true);
473
-    }
474
-
475
-
476
-    /**
477
-     * Setup headers for email
478
-     *
479
-     * @access protected
480
-     * @return string formatted header for email
481
-     */
482
-    protected function _headers()
483
-    {
484
-        $this->_ensure_has_from_email_address();
485
-        $from    = $this->_from;
486
-        $headers = array(
487
-            'From:' . $from,
488
-            'Reply-To:' . $from,
489
-            'Content-Type:text/html; charset=utf-8',
490
-        );
491
-
492
-        if (! empty($this->_cc)) {
493
-            $headers[] = 'cc: ' . $this->_cc;
494
-        }
495
-
496
-        //but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
497
-        // header.
498
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
499
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
500
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
501
-    }
502
-
503
-
504
-    /**
505
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
506
-     * address for the from address to avoid problems with sending emails.
507
-     */
508
-    protected function _ensure_has_from_email_address()
509
-    {
510
-        if (empty($this->_from)) {
511
-            $this->_from = get_bloginfo('admin_email');
512
-        }
513
-    }
514
-
515
-
516
-    /**
517
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
518
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
519
-     * be empty
520
-     *
521
-     * @since 4.3.1
522
-     * @return array
523
-     */
524
-    private function _parse_from()
525
-    {
526
-        if (strpos($this->_from, '<') !== false) {
527
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
528
-            $from_name = str_replace('"', '', $from_name);
529
-            $from_name = trim($from_name);
530
-
531
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
532
-            $from_email = str_replace('>', '', $from_email);
533
-            $from_email = trim($from_email);
534
-        } elseif (trim($this->_from) !== '') {
535
-            $from_name  = '';
536
-            $from_email = trim($this->_from);
537
-        } else {
538
-            $from_name = $from_email = '';
539
-        }
540
-        return array($from_name, $from_email);
541
-    }
542
-
543
-
544
-    /**
545
-     * Callback for the wp_mail_from filter.
546
-     *
547
-     * @since 4.3.1
548
-     * @param string $from_email What the original from_email is.
549
-     * @return string
550
-     */
551
-    public function set_from_address($from_email)
552
-    {
553
-        $parsed_from = $this->_parse_from();
554
-        //includes fallback if the parsing failed.
555
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
556
-            ? $parsed_from[1]
557
-            : get_bloginfo('admin_email');
558
-        return $from_email;
559
-    }
560
-
561
-
562
-    /**
563
-     * Callback fro the wp_mail_from_name filter.
564
-     *
565
-     * @since 4.3.1
566
-     * @param string $from_name The original from_name.
567
-     * @return string
568
-     */
569
-    public function set_from_name($from_name)
570
-    {
571
-        $parsed_from = $this->_parse_from();
572
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
573
-            $from_name = $parsed_from[0];
574
-        }
575
-
576
-        //if from name is "WordPress" let's sub in the site name instead (more friendly!)
577
-        //but realize the default name is HTML entity-encoded
578
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
579
-
580
-        return $from_name;
581
-    }
582
-
583
-
584
-    /**
585
-     * setup body for email
586
-     *
587
-     * @param bool $preview will determine whether this is preview template or not.
588
-     * @return string formatted body for email.
589
-     * @throws EE_Error
590
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
591
-     */
592
-    protected function _body($preview = false)
593
-    {
594
-        //setup template args!
595
-        $this->_template_args = array(
596
-            'subject'   => $this->_subject,
597
-            'from'      => $this->_from,
598
-            'main_body' => wpautop($this->_content),
599
-        );
600
-        $body                 = $this->_get_main_template($preview);
601
-
602
-        /**
603
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
604
-         *
605
-         * @type    bool $preview Indicates whether a preview is being generated or not.
606
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
607
-         */
608
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
609
-            //require CssToInlineStyles library and its dependencies via composer autoloader
610
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
611
-
612
-            //now if this isn't a preview, let's setup the body so it has inline styles
613
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
614
-                $style = file_get_contents(
615
-                    $this->get_variation(
616
-                        $this->_tmp_pack,
617
-                        $this->_incoming_message_type->name,
618
-                        false,
619
-                        'main',
620
-                        $this->_variation
621
-                    ),
622
-                    true
623
-                );
624
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
625
-                //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
626
-                $body  = ltrim($CSS->convert(true), ">\n");
627
-                //see https://events.codebasehq.com/projects/event-espresso/tickets/8609
628
-                $body  = ltrim($body, "<?");
629
-            }
630
-
631
-        }
632
-        return $body;
633
-    }
634
-
635
-
636
-    /**
637
-     * This just returns any existing test settings that might be saved in the database
638
-     *
639
-     * @access public
640
-     * @return array
641
-     */
642
-    public function get_existing_test_settings()
643
-    {
644
-        $settings = parent::get_existing_test_settings();
645
-        //override subject if present because we always want it to be fresh.
646
-        if (is_array($settings) && ! empty($settings['subject'])) {
647
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
648
-        }
649
-        return $settings;
650
-    }
11
+	/**
12
+	 * To field for email
13
+	 * @var string
14
+	 */
15
+	protected $_to = '';
16
+
17
+
18
+	/**
19
+	 * CC field for email.
20
+	 * @var string
21
+	 */
22
+	protected $_cc = '';
23
+
24
+	/**
25
+	 * From field for email
26
+	 * @var string
27
+	 */
28
+	protected $_from = '';
29
+
30
+
31
+	/**
32
+	 * Subject field for email
33
+	 * @var string
34
+	 */
35
+	protected $_subject = '';
36
+
37
+
38
+	/**
39
+	 * Content field for email
40
+	 * @var string
41
+	 */
42
+	protected $_content = '';
43
+
44
+
45
+	/**
46
+	 * constructor
47
+	 *
48
+	 * @access public
49
+	 */
50
+	public function __construct()
51
+	{
52
+		//set name and description properties
53
+		$this->name                = 'email';
54
+		$this->description         = sprintf(
55
+			esc_html__(
56
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
57
+				'event_espresso'
58
+			),
59
+			'<code>wp_mail</code>'
60
+		);
61
+		$this->label               = array(
62
+			'singular' => esc_html__('email', 'event_espresso'),
63
+			'plural'   => esc_html__('emails', 'event_espresso'),
64
+		);
65
+		$this->activate_on_install = true;
66
+
67
+		//we're using defaults so let's call parent constructor that will take care of setting up all the other
68
+		// properties
69
+		parent::__construct();
70
+	}
71
+
72
+
73
+	/**
74
+	 * see abstract declaration in parent class for details.
75
+	 */
76
+	protected function _set_admin_pages()
77
+	{
78
+		$this->admin_registered_pages = array(
79
+			'events_edit' => true,
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * see abstract declaration in parent class for details
86
+	 */
87
+	protected function _set_valid_shortcodes()
88
+	{
89
+		//remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
90
+		// message type.
91
+		$this->_valid_shortcodes = array(
92
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
94
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
95
+		);
96
+	}
97
+
98
+
99
+	/**
100
+	 * see abstract declaration in parent class for details
101
+	 *
102
+	 * @access protected
103
+	 * @return void
104
+	 */
105
+	protected function _set_validator_config()
106
+	{
107
+		$valid_shortcodes = $this->get_valid_shortcodes();
108
+
109
+		$this->_validator_config = array(
110
+			'to'            => array(
111
+				'shortcodes' => $valid_shortcodes['to'],
112
+				'type'       => 'email',
113
+			),
114
+			'cc' => array(
115
+				'shortcodes' => $valid_shortcodes['to'],
116
+				'type' => 'email',
117
+			),
118
+			'from'          => array(
119
+				'shortcodes' => $valid_shortcodes['from'],
120
+				'type'       => 'email',
121
+			),
122
+			'subject'       => array(
123
+				'shortcodes' => array(
124
+					'organization',
125
+					'primary_registration_details',
126
+					'event_author',
127
+					'primary_registration_details',
128
+					'recipient_details',
129
+				),
130
+			),
131
+			'content'       => array(
132
+				'shortcodes' => array(
133
+					'event_list',
134
+					'attendee_list',
135
+					'ticket_list',
136
+					'organization',
137
+					'primary_registration_details',
138
+					'primary_registration_list',
139
+					'event_author',
140
+					'recipient_details',
141
+					'recipient_list',
142
+					'transaction',
143
+					'messenger',
144
+				),
145
+			),
146
+			'attendee_list' => array(
147
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
148
+				'required'   => array('[ATTENDEE_LIST]'),
149
+			),
150
+			'event_list'    => array(
151
+				'shortcodes' => array(
152
+					'event',
153
+					'attendee_list',
154
+					'ticket_list',
155
+					'venue',
156
+					'datetime_list',
157
+					'attendee',
158
+					'primary_registration_details',
159
+					'primary_registration_list',
160
+					'event_author',
161
+					'recipient_details',
162
+					'recipient_list',
163
+				),
164
+				'required'   => array('[EVENT_LIST]'),
165
+			),
166
+			'ticket_list'   => array(
167
+				'shortcodes' => array(
168
+					'event_list',
169
+					'attendee_list',
170
+					'ticket',
171
+					'datetime_list',
172
+					'primary_registration_details',
173
+					'recipient_details',
174
+				),
175
+				'required'   => array('[TICKET_LIST]'),
176
+			),
177
+			'datetime_list' => array(
178
+				'shortcodes' => array('datetime'),
179
+				'required'   => array('[DATETIME_LIST]'),
180
+			),
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * @see   parent EE_messenger class for docs
187
+	 * @since 4.5.0
188
+	 */
189
+	public function do_secondary_messenger_hooks($sending_messenger_name)
190
+	{
191
+		if ($sending_messenger_name = 'html') {
192
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
193
+		}
194
+	}
195
+
196
+
197
+	public function add_email_css(
198
+		$variation_path,
199
+		$messenger,
200
+		$message_type,
201
+		$type,
202
+		$variation,
203
+		$file_extension,
204
+		$url,
205
+		EE_Messages_Template_Pack $template_pack
206
+	) {
207
+		//prevent recursion on this callback.
208
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
209
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
210
+
211
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
212
+		return $variation;
213
+	}
214
+
215
+
216
+	/**
217
+	 * See parent for details
218
+	 *
219
+	 * @access protected
220
+	 * @return void
221
+	 */
222
+	protected function _set_test_settings_fields()
223
+	{
224
+		$this->_test_settings_fields = array(
225
+			'to'      => array(
226
+				'input'      => 'text',
227
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
228
+				'type'       => 'email',
229
+				'required'   => true,
230
+				'validation' => true,
231
+				'css_class'  => 'large-text',
232
+				'format'     => '%s',
233
+				'default'    => get_bloginfo('admin_email'),
234
+			),
235
+			'subject' => array(
236
+				'input'      => 'hidden',
237
+				'label'      => '',
238
+				'type'       => 'string',
239
+				'required'   => false,
240
+				'validation' => false,
241
+				'format'     => '%s',
242
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
243
+				'default'    => '',
244
+				'css_class'  => '',
245
+			),
246
+		);
247
+	}
248
+
249
+
250
+	/**
251
+	 * _set_template_fields
252
+	 * This sets up the fields that a messenger requires for the message to go out.
253
+	 *
254
+	 * @access  protected
255
+	 * @return void
256
+	 */
257
+	protected function _set_template_fields()
258
+	{
259
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
260
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
261
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
262
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
263
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
264
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
265
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
266
+		// will not be displayed/parsed.
267
+		$this->_template_fields = array(
268
+			'to'      => array(
269
+				'input'      => 'text',
270
+				'label'      => esc_html_x(
271
+					'To',
272
+					'Label for the "To" field for email addresses',
273
+					'event_espresso'
274
+				),
275
+				'type'       => 'string',
276
+				'required'   => true,
277
+				'validation' => true,
278
+				'css_class'  => 'large-text',
279
+				'format'     => '%s',
280
+			),
281
+			'cc'      => array(
282
+				'input'      => 'text',
283
+				'label'      => esc_html_x(
284
+					'CC',
285
+					'Label for the "Carbon Copy" field used for additional email addresses',
286
+					'event_espresso'
287
+				),
288
+				'type'       => 'string',
289
+				'required'   => false,
290
+				'validation' => true,
291
+				'css_class'  => 'large-text',
292
+				'format'     => '%s',
293
+			),
294
+			'from'    => array(
295
+				'input'      => 'text',
296
+				'label'      => esc_html_x(
297
+					'From',
298
+					'Label for the "From" field for email addresses.',
299
+					'event_espresso'
300
+				),
301
+				'type'       => 'string',
302
+				'required'   => true,
303
+				'validation' => true,
304
+				'css_class'  => 'large-text',
305
+				'format'     => '%s',
306
+			),
307
+			'subject' => array(
308
+				'input'      => 'text',
309
+				'label'      => esc_html_x(
310
+					'Subject',
311
+					'Label for the "Subject" field (short description of contents) for emails.',
312
+					'event_espresso'
313
+				),
314
+				'type'       => 'string',
315
+				'required'   => true,
316
+				'validation' => true,
317
+				'css_class'  => 'large-text',
318
+				'format'     => '%s',
319
+			),
320
+			'content' => '',
321
+			//left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
322
+			'extra'   => array(
323
+				'content' => array(
324
+					'main'          => array(
325
+						'input'      => 'wp_editor',
326
+						'label'      => esc_html__('Main Content', 'event_espresso'),
327
+						'type'       => 'string',
328
+						'required'   => true,
329
+						'validation' => true,
330
+						'format'     => '%s',
331
+						'rows'       => '15',
332
+					),
333
+					'event_list'    => array(
334
+						'input'               => 'wp_editor',
335
+						'label'               => '[EVENT_LIST]',
336
+						'type'                => 'string',
337
+						'required'            => true,
338
+						'validation'          => true,
339
+						'format'              => '%s',
340
+						'rows'                => '15',
341
+						'shortcodes_required' => array('[EVENT_LIST]'),
342
+					),
343
+					'attendee_list' => array(
344
+						'input'               => 'textarea',
345
+						'label'               => '[ATTENDEE_LIST]',
346
+						'type'                => 'string',
347
+						'required'            => true,
348
+						'validation'          => true,
349
+						'format'              => '%s',
350
+						'css_class'           => 'large-text',
351
+						'rows'                => '5',
352
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
353
+					),
354
+					'ticket_list'   => array(
355
+						'input'               => 'textarea',
356
+						'label'               => '[TICKET_LIST]',
357
+						'type'                => 'string',
358
+						'required'            => true,
359
+						'validation'          => true,
360
+						'format'              => '%s',
361
+						'css_class'           => 'large-text',
362
+						'rows'                => '10',
363
+						'shortcodes_required' => array('[TICKET_LIST]'),
364
+					),
365
+					'datetime_list' => array(
366
+						'input'               => 'textarea',
367
+						'label'               => '[DATETIME_LIST]',
368
+						'type'                => 'string',
369
+						'required'            => true,
370
+						'validation'          => true,
371
+						'format'              => '%s',
372
+						'css_class'           => 'large-text',
373
+						'rows'                => '10',
374
+						'shortcodes_required' => array('[DATETIME_LIST]'),
375
+					),
376
+				),
377
+			),
378
+		);
379
+	}
380
+
381
+
382
+	/**
383
+	 * See definition of this class in parent
384
+	 */
385
+	protected function _set_default_message_types()
386
+	{
387
+		$this->_default_message_types = array(
388
+			'payment',
389
+			'payment_refund',
390
+			'registration',
391
+			'not_approved_registration',
392
+			'pending_approval',
393
+		);
394
+	}
395
+
396
+
397
+	/**
398
+	 * @see   definition of this class in parent
399
+	 * @since 4.5.0
400
+	 */
401
+	protected function _set_valid_message_types()
402
+	{
403
+		$this->_valid_message_types = array(
404
+			'payment',
405
+			'registration',
406
+			'not_approved_registration',
407
+			'declined_registration',
408
+			'cancelled_registration',
409
+			'pending_approval',
410
+			'registration_summary',
411
+			'payment_reminder',
412
+			'payment_declined',
413
+			'payment_refund',
414
+		);
415
+	}
416
+
417
+
418
+	/**
419
+	 * setting up admin_settings_fields for messenger.
420
+	 */
421
+	protected function _set_admin_settings_fields()
422
+	{
423
+	}
424
+
425
+	/**
426
+	 * We just deliver the messages don't kill us!!
427
+	 *
428
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
429
+	 *              present.
430
+	 * @throws EE_Error
431
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
432
+	 */
433
+	protected function _send_message()
434
+	{
435
+		$success = wp_mail(
436
+			$this->_to,
437
+			//some old values for subject may be expecting HTML entities to be decoded in the subject
438
+			//and subjects aren't interpreted as HTML, so there should be no HTML in them
439
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
440
+			$this->_body(),
441
+			$this->_headers()
442
+		);
443
+		if (! $success) {
444
+			EE_Error::add_error(
445
+				sprintf(
446
+					esc_html__(
447
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
448
+						'event_espresso'
449
+					),
450
+					$this->_to,
451
+					$this->_from,
452
+					'<br />'
453
+				),
454
+				__FILE__,
455
+				__FUNCTION__,
456
+				__LINE__
457
+			);
458
+		}
459
+		return $success;
460
+	}
461
+
462
+
463
+	/**
464
+	 * see parent for definition
465
+	 *
466
+	 * @return string html body of the message content and the related css.
467
+	 * @throws EE_Error
468
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
469
+	 */
470
+	protected function _preview()
471
+	{
472
+		return $this->_body(true);
473
+	}
474
+
475
+
476
+	/**
477
+	 * Setup headers for email
478
+	 *
479
+	 * @access protected
480
+	 * @return string formatted header for email
481
+	 */
482
+	protected function _headers()
483
+	{
484
+		$this->_ensure_has_from_email_address();
485
+		$from    = $this->_from;
486
+		$headers = array(
487
+			'From:' . $from,
488
+			'Reply-To:' . $from,
489
+			'Content-Type:text/html; charset=utf-8',
490
+		);
491
+
492
+		if (! empty($this->_cc)) {
493
+			$headers[] = 'cc: ' . $this->_cc;
494
+		}
495
+
496
+		//but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
497
+		// header.
498
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
499
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
500
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
501
+	}
502
+
503
+
504
+	/**
505
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
506
+	 * address for the from address to avoid problems with sending emails.
507
+	 */
508
+	protected function _ensure_has_from_email_address()
509
+	{
510
+		if (empty($this->_from)) {
511
+			$this->_from = get_bloginfo('admin_email');
512
+		}
513
+	}
514
+
515
+
516
+	/**
517
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
518
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
519
+	 * be empty
520
+	 *
521
+	 * @since 4.3.1
522
+	 * @return array
523
+	 */
524
+	private function _parse_from()
525
+	{
526
+		if (strpos($this->_from, '<') !== false) {
527
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
528
+			$from_name = str_replace('"', '', $from_name);
529
+			$from_name = trim($from_name);
530
+
531
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
532
+			$from_email = str_replace('>', '', $from_email);
533
+			$from_email = trim($from_email);
534
+		} elseif (trim($this->_from) !== '') {
535
+			$from_name  = '';
536
+			$from_email = trim($this->_from);
537
+		} else {
538
+			$from_name = $from_email = '';
539
+		}
540
+		return array($from_name, $from_email);
541
+	}
542
+
543
+
544
+	/**
545
+	 * Callback for the wp_mail_from filter.
546
+	 *
547
+	 * @since 4.3.1
548
+	 * @param string $from_email What the original from_email is.
549
+	 * @return string
550
+	 */
551
+	public function set_from_address($from_email)
552
+	{
553
+		$parsed_from = $this->_parse_from();
554
+		//includes fallback if the parsing failed.
555
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
556
+			? $parsed_from[1]
557
+			: get_bloginfo('admin_email');
558
+		return $from_email;
559
+	}
560
+
561
+
562
+	/**
563
+	 * Callback fro the wp_mail_from_name filter.
564
+	 *
565
+	 * @since 4.3.1
566
+	 * @param string $from_name The original from_name.
567
+	 * @return string
568
+	 */
569
+	public function set_from_name($from_name)
570
+	{
571
+		$parsed_from = $this->_parse_from();
572
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
573
+			$from_name = $parsed_from[0];
574
+		}
575
+
576
+		//if from name is "WordPress" let's sub in the site name instead (more friendly!)
577
+		//but realize the default name is HTML entity-encoded
578
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
579
+
580
+		return $from_name;
581
+	}
582
+
583
+
584
+	/**
585
+	 * setup body for email
586
+	 *
587
+	 * @param bool $preview will determine whether this is preview template or not.
588
+	 * @return string formatted body for email.
589
+	 * @throws EE_Error
590
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
591
+	 */
592
+	protected function _body($preview = false)
593
+	{
594
+		//setup template args!
595
+		$this->_template_args = array(
596
+			'subject'   => $this->_subject,
597
+			'from'      => $this->_from,
598
+			'main_body' => wpautop($this->_content),
599
+		);
600
+		$body                 = $this->_get_main_template($preview);
601
+
602
+		/**
603
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
604
+		 *
605
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
606
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
607
+		 */
608
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
609
+			//require CssToInlineStyles library and its dependencies via composer autoloader
610
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
611
+
612
+			//now if this isn't a preview, let's setup the body so it has inline styles
613
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
614
+				$style = file_get_contents(
615
+					$this->get_variation(
616
+						$this->_tmp_pack,
617
+						$this->_incoming_message_type->name,
618
+						false,
619
+						'main',
620
+						$this->_variation
621
+					),
622
+					true
623
+				);
624
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
625
+				//for some reason the library has a bracket and new line at the beginning.  This takes care of that.
626
+				$body  = ltrim($CSS->convert(true), ">\n");
627
+				//see https://events.codebasehq.com/projects/event-espresso/tickets/8609
628
+				$body  = ltrim($body, "<?");
629
+			}
630
+
631
+		}
632
+		return $body;
633
+	}
634
+
635
+
636
+	/**
637
+	 * This just returns any existing test settings that might be saved in the database
638
+	 *
639
+	 * @access public
640
+	 * @return array
641
+	 */
642
+	public function get_existing_test_settings()
643
+	{
644
+		$settings = parent::get_existing_test_settings();
645
+		//override subject if present because we always want it to be fresh.
646
+		if (is_array($settings) && ! empty($settings['subject'])) {
647
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
648
+		}
649
+		return $settings;
650
+	}
651 651
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.001');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.001');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118
-        /**
119
-         *    espresso_load_error_handling
120
-         *    this function loads EE's class for handling exceptions and errors
121
-         */
122
-        function espresso_load_error_handling()
123
-        {
124
-            static $error_handling_loaded = false;
125
-            if ($error_handling_loaded) {
126
-                return;
127
-            }
128
-            // load debugging tools
129
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
-                \EEH_Debug_Tools::instance();
132
-            }
133
-            // load error handling
134
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
-                require_once EE_CORE . 'EE_Error.core.php';
136
-            } else {
137
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
-            }
139
-            $error_handling_loaded = true;
140
-        }
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118
+		/**
119
+		 *    espresso_load_error_handling
120
+		 *    this function loads EE's class for handling exceptions and errors
121
+		 */
122
+		function espresso_load_error_handling()
123
+		{
124
+			static $error_handling_loaded = false;
125
+			if ($error_handling_loaded) {
126
+				return;
127
+			}
128
+			// load debugging tools
129
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
+				\EEH_Debug_Tools::instance();
132
+			}
133
+			// load error handling
134
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
+				require_once EE_CORE . 'EE_Error.core.php';
136
+			} else {
137
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
+			}
139
+			$error_handling_loaded = true;
140
+		}
141 141
 
142
-        /**
143
-         *    espresso_load_required
144
-         *    given a class name and path, this function will load that file or throw an exception
145
-         *
146
-         * @param    string $classname
147
-         * @param    string $full_path_to_file
148
-         * @throws    EE_Error
149
-         */
150
-        function espresso_load_required($classname, $full_path_to_file)
151
-        {
152
-            if (is_readable($full_path_to_file)) {
153
-                require_once $full_path_to_file;
154
-            } else {
155
-                throw new \EE_Error (
156
-                    sprintf(
157
-                        esc_html__(
158
-                            'The %s class file could not be located or is not readable due to file permissions.',
159
-                            'event_espresso'
160
-                        ),
161
-                        $classname
162
-                    )
163
-                );
164
-            }
165
-        }
142
+		/**
143
+		 *    espresso_load_required
144
+		 *    given a class name and path, this function will load that file or throw an exception
145
+		 *
146
+		 * @param    string $classname
147
+		 * @param    string $full_path_to_file
148
+		 * @throws    EE_Error
149
+		 */
150
+		function espresso_load_required($classname, $full_path_to_file)
151
+		{
152
+			if (is_readable($full_path_to_file)) {
153
+				require_once $full_path_to_file;
154
+			} else {
155
+				throw new \EE_Error (
156
+					sprintf(
157
+						esc_html__(
158
+							'The %s class file could not be located or is not readable due to file permissions.',
159
+							'event_espresso'
160
+						),
161
+						$classname
162
+					)
163
+				);
164
+			}
165
+		}
166 166
 
167
-        /**
168
-         * @since 4.9.27
169
-         * @throws \EE_Error
170
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
174
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
-         * @throws \OutOfBoundsException
178
-         */
179
-        function bootstrap_espresso()
180
-        {
181
-            require_once __DIR__ . '/core/espresso_definitions.php';
182
-            try {
183
-                espresso_load_error_handling();
184
-                espresso_load_required(
185
-                    'EEH_Base',
186
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
-                );
188
-                espresso_load_required(
189
-                    'EEH_File',
190
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
-                );
192
-                espresso_load_required(
193
-                    'EEH_File',
194
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
-                );
196
-                espresso_load_required(
197
-                    'EEH_Array',
198
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
-                );
200
-                // instantiate and configure PSR4 autoloader
201
-                espresso_load_required(
202
-                    'Psr4Autoloader',
203
-                    EE_CORE . 'Psr4Autoloader.php'
204
-                );
205
-                espresso_load_required(
206
-                    'EE_Psr4AutoloaderInit',
207
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
-                );
209
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
210
-                $AutoloaderInit->initializeAutoloader();
211
-                espresso_load_required(
212
-                    'EE_Request',
213
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
-                );
215
-                espresso_load_required(
216
-                    'EE_Response',
217
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
-                );
219
-                espresso_load_required(
220
-                    'EE_Bootstrap',
221
-                    EE_CORE . 'EE_Bootstrap.core.php'
222
-                );
223
-                // bootstrap EE and the request stack
224
-                new EE_Bootstrap(
225
-                    new EE_Request($_GET, $_POST, $_COOKIE),
226
-                    new EE_Response()
227
-                );
228
-            } catch (Exception $e) {
229
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
-            }
232
-        }
233
-        bootstrap_espresso();
234
-    }
167
+		/**
168
+		 * @since 4.9.27
169
+		 * @throws \EE_Error
170
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
+		 * @throws \OutOfBoundsException
178
+		 */
179
+		function bootstrap_espresso()
180
+		{
181
+			require_once __DIR__ . '/core/espresso_definitions.php';
182
+			try {
183
+				espresso_load_error_handling();
184
+				espresso_load_required(
185
+					'EEH_Base',
186
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
+				);
188
+				espresso_load_required(
189
+					'EEH_File',
190
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
+				);
192
+				espresso_load_required(
193
+					'EEH_File',
194
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
+				);
196
+				espresso_load_required(
197
+					'EEH_Array',
198
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
+				);
200
+				// instantiate and configure PSR4 autoloader
201
+				espresso_load_required(
202
+					'Psr4Autoloader',
203
+					EE_CORE . 'Psr4Autoloader.php'
204
+				);
205
+				espresso_load_required(
206
+					'EE_Psr4AutoloaderInit',
207
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
+				);
209
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
210
+				$AutoloaderInit->initializeAutoloader();
211
+				espresso_load_required(
212
+					'EE_Request',
213
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
+				);
215
+				espresso_load_required(
216
+					'EE_Response',
217
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
+				);
219
+				espresso_load_required(
220
+					'EE_Bootstrap',
221
+					EE_CORE . 'EE_Bootstrap.core.php'
222
+				);
223
+				// bootstrap EE and the request stack
224
+				new EE_Bootstrap(
225
+					new EE_Request($_GET, $_POST, $_COOKIE),
226
+					new EE_Response()
227
+				);
228
+			} catch (Exception $e) {
229
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
+			}
232
+		}
233
+		bootstrap_espresso();
234
+	}
235 235
 }
236 236
 if (! function_exists('espresso_deactivate_plugin')) {
237
-    /**
238
-     *    deactivate_plugin
239
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
-     *
241
-     * @access public
242
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
-     * @return    void
244
-     */
245
-    function espresso_deactivate_plugin($plugin_basename = '')
246
-    {
247
-        if (! function_exists('deactivate_plugins')) {
248
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
-        }
250
-        unset($_GET['activate'], $_REQUEST['activate']);
251
-        deactivate_plugins($plugin_basename);
252
-    }
237
+	/**
238
+	 *    deactivate_plugin
239
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
+	 *
241
+	 * @access public
242
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
+	 * @return    void
244
+	 */
245
+	function espresso_deactivate_plugin($plugin_basename = '')
246
+	{
247
+		if (! function_exists('deactivate_plugins')) {
248
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
+		}
250
+		unset($_GET['activate'], $_REQUEST['activate']);
251
+		deactivate_plugins($plugin_basename);
252
+	}
253 253
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +1858 added lines, -1858 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1863 +20,1863 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * load_reg_steps
242
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
-     *
244
-     * @access    private
245
-     * @throws EE_Error
246
-     */
247
-    public static function load_reg_steps()
248
-    {
249
-        static $reg_steps_loaded = false;
250
-        if ($reg_steps_loaded) {
251
-            return;
252
-        }
253
-        // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
255
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
-            EED_Single_Page_Checkout::get_reg_steps()
257
-        );
258
-        // sort by key (order)
259
-        ksort($reg_steps_to_load);
260
-        // loop through folders
261
-        foreach ($reg_steps_to_load as $order => $reg_step) {
262
-            // we need a
263
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
-                // copy over to the reg_steps_array
265
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
-                // register custom key route for each reg step
267
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
-                EE_Config::register_route(
269
-                    $reg_step['slug'],
270
-                    'EED_Single_Page_Checkout',
271
-                    'run',
272
-                    'step'
273
-                );
274
-                // add AJAX or other hooks
275
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
-                    // setup autoloaders if necessary
277
-                    if ( ! class_exists($reg_step['class_name'])) {
278
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
-                            $reg_step['file_path'],
280
-                            true
281
-                        );
282
-                    }
283
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
-                    }
286
-                }
287
-            }
288
-        }
289
-        $reg_steps_loaded = true;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     *    get_reg_steps
296
-     *
297
-     * @access    public
298
-     * @return    array
299
-     */
300
-    public static function get_reg_steps()
301
-    {
302
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
-        if (empty($reg_steps)) {
304
-            $reg_steps = array(
305
-                10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
-                    'slug'       => 'attendee_information',
309
-                    'has_hooks'  => false,
310
-                ),
311
-                20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
-                    'slug'       => 'registration_confirmation',
315
-                    'has_hooks'  => false,
316
-                ),
317
-                30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
-                    'slug'       => 'payment_options',
321
-                    'has_hooks'  => true,
322
-                ),
323
-                999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
-                    'slug'       => 'finalize_registration',
327
-                    'has_hooks'  => false,
328
-                ),
329
-            );
330
-        }
331
-        return $reg_steps;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     *    registration_checkout_for_admin
338
-     *
339
-     * @access    public
340
-     * @return    string
341
-     * @throws EE_Error
342
-     */
343
-    public static function registration_checkout_for_admin()
344
-    {
345
-        EED_Single_Page_Checkout::load_request_handler();
346
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
349
-        EED_Single_Page_Checkout::instance()->_initialize();
350
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
-        return EE_Registry::instance()->REQ->get_output();
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * process_registration_from_admin
358
-     *
359
-     * @access public
360
-     * @return \EE_Transaction
361
-     * @throws EE_Error
362
-     */
363
-    public static function process_registration_from_admin()
364
-    {
365
-        EED_Single_Page_Checkout::load_request_handler();
366
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
369
-        EED_Single_Page_Checkout::instance()->_initialize();
370
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
-                if ($final_reg_step->process_reg_step()) {
375
-                    $final_reg_step->set_completed();
376
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
-                }
379
-            }
380
-        }
381
-        return null;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     *    run
388
-     *
389
-     * @access    public
390
-     * @param WP_Query $WP_Query
391
-     * @return    void
392
-     * @throws EE_Error
393
-     */
394
-    public function run($WP_Query)
395
-    {
396
-        if (
397
-            $WP_Query instanceof WP_Query
398
-            && $WP_Query->is_main_query()
399
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
-            && $this->_is_reg_checkout()
401
-        ) {
402
-            $this->_initialize();
403
-        }
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * determines whether current url matches reg page url
410
-     *
411
-     * @return bool
412
-     */
413
-    protected function _is_reg_checkout()
414
-    {
415
-        // get current permalink for reg page without any extra query args
416
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
-        // get request URI for current request, but without the scheme or host
418
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
-        $current_request_uri = html_entity_decode($current_request_uri);
420
-        // get array of query args from the current request URI
421
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
422
-        // grab page id if it is set
423
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
-        // and remove the page id from the query args (we will re-add it later)
425
-        unset($query_args['page_id']);
426
-        // now strip all query args from current request URI
427
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
-        // and re-add the page id if it was set
429
-        if ($page_id) {
430
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
-        }
432
-        // remove slashes and ?
433
-        $current_request_uri = trim($current_request_uri, '?/');
434
-        // is current request URI part of the known full reg page URL ?
435
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     * @param WP_Query $wp_query
442
-     * @return    void
443
-     * @throws EE_Error
444
-     */
445
-    public static function init($wp_query)
446
-    {
447
-        EED_Single_Page_Checkout::instance()->run($wp_query);
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     *    _initialize - initial module setup
454
-     *
455
-     * @access    private
456
-     * @throws EE_Error
457
-     * @return    void
458
-     */
459
-    private function _initialize()
460
-    {
461
-        // ensure SPCO doesn't run twice
462
-        if (EED_Single_Page_Checkout::$_initialized) {
463
-            return;
464
-        }
465
-        try {
466
-            EED_Single_Page_Checkout::load_reg_steps();
467
-            $this->_verify_session();
468
-            // setup the EE_Checkout object
469
-            $this->checkout = $this->_initialize_checkout();
470
-            // filter checkout
471
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
-            // get the $_GET
473
-            $this->_get_request_vars();
474
-            if ($this->_block_bots()) {
475
-                return;
476
-            }
477
-            // filter continue_reg
478
-            $this->checkout->continue_reg = apply_filters(
479
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
-                true,
481
-                $this->checkout
482
-            );
483
-            // load the reg steps array
484
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
485
-                EED_Single_Page_Checkout::$_initialized = true;
486
-                return;
487
-            }
488
-            // set the current step
489
-            $this->checkout->set_current_step($this->checkout->step);
490
-            // and the next step
491
-            $this->checkout->set_next_step();
492
-            // verify that everything has been setup correctly
493
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
-                EED_Single_Page_Checkout::$_initialized = true;
495
-                return;
496
-            }
497
-            // lock the transaction
498
-            $this->checkout->transaction->lock();
499
-            // make sure all of our cached objects are added to their respective model entity mappers
500
-            $this->checkout->refresh_all_entities();
501
-            // set amount owing
502
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
-            // initialize each reg step, which gives them the chance to potentially alter the process
504
-            $this->_initialize_reg_steps();
505
-            // DEBUG LOG
506
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
-            // get reg form
508
-            if( ! $this->_check_form_submission()) {
509
-                EED_Single_Page_Checkout::$_initialized = true;
510
-                return;
511
-            }
512
-            // checkout the action!!!
513
-            $this->_process_form_action();
514
-            // add some style and make it dance
515
-            $this->add_styles_and_scripts();
516
-            // kk... SPCO has successfully run
517
-            EED_Single_Page_Checkout::$_initialized = true;
518
-            // set no cache headers and constants
519
-            EE_System::do_not_cache();
520
-            // add anchor
521
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
-            // remove transaction lock
523
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
-        } catch (Exception $e) {
525
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
-        }
527
-    }
528
-
529
-
530
-
531
-    /**
532
-     *    _verify_session
533
-     * checks that the session is valid and not expired
534
-     *
535
-     * @access    private
536
-     * @throws EE_Error
537
-     */
538
-    private function _verify_session()
539
-    {
540
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
-        }
543
-        $clear_session_requested = filter_var(
544
-            EE_Registry::instance()->REQ->get('clear_session', false),
545
-            FILTER_VALIDATE_BOOLEAN
546
-        );
547
-        // is session still valid ?
548
-        if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
550
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
-            )
552
-        ) {
553
-            $this->checkout = new EE_Checkout();
554
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
-            // EE_Registry::instance()->SSN->reset_cart();
556
-            // EE_Registry::instance()->SSN->reset_checkout();
557
-            // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
559
-                EE_Error::add_attention(
560
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
-                    __FILE__, __FUNCTION__, __LINE__
562
-                );
563
-            }
564
-            // EE_Registry::instance()->SSN->reset_expired();
565
-        }
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     *    _initialize_checkout
572
-     * loads and instantiates EE_Checkout
573
-     *
574
-     * @access    private
575
-     * @throws EE_Error
576
-     * @return EE_Checkout
577
-     */
578
-    private function _initialize_checkout()
579
-    {
580
-        // look in session for existing checkout
581
-        /** @type EE_Checkout $checkout */
582
-        $checkout = EE_Registry::instance()->SSN->checkout();
583
-        // verify
584
-        if ( ! $checkout instanceof EE_Checkout) {
585
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
586
-            $checkout = EE_Registry::instance()->load_file(
587
-                SPCO_INC_PATH,
588
-                'EE_Checkout',
589
-                'class', array(),
590
-                false
591
-            );
592
-        } else {
593
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
-                $this->unlock_transaction();
595
-                wp_safe_redirect($checkout->redirect_url);
596
-                exit();
597
-            }
598
-        }
599
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
-        // verify again
601
-        if ( ! $checkout instanceof EE_Checkout) {
602
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
-        }
604
-        // reset anything that needs a clean slate for each request
605
-        $checkout->reset_for_current_request();
606
-        return $checkout;
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     *    _get_request_vars
613
-     *
614
-     * @access    private
615
-     * @return    void
616
-     * @throws EE_Error
617
-     */
618
-    private function _get_request_vars()
619
-    {
620
-        // load classes
621
-        EED_Single_Page_Checkout::load_request_handler();
622
-        //make sure this request is marked as belonging to EE
623
-        EE_Registry::instance()->REQ->set_espresso_page(true);
624
-        // which step is being requested ?
625
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
-        // which step is being edited ?
627
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
-        // and what we're doing on the current step
629
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
-        // timestamp
631
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
-        // returning to edit ?
633
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
-        // add reg url link to registration query params
635
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
-        }
638
-        // or some other kind of revisit ?
639
-        $this->checkout->revisit = filter_var(
640
-            EE_Registry::instance()->REQ->get('revisit', false),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to generate a reg form for this request
644
-        $this->checkout->generate_reg_form = filter_var(
645
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
-            FILTER_VALIDATE_BOOLEAN
647
-        );
648
-        // and whether or not to process a reg form submission for this request
649
-        $this->checkout->process_form_submission = filter_var(
650
-            EE_Registry::instance()->REQ->get(
651
-                'process_form_submission',
652
-                $this->checkout->action === 'process_reg_step'
653
-            ),
654
-            FILTER_VALIDATE_BOOLEAN
655
-        );
656
-        $this->checkout->process_form_submission = filter_var(
657
-            $this->checkout->action !== 'display_spco_reg_step'
658
-                ? $this->checkout->process_form_submission
659
-                : false,
660
-            FILTER_VALIDATE_BOOLEAN
661
-        );
662
-        // $this->_display_request_vars();
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     *  _display_request_vars
669
-     *
670
-     * @access    protected
671
-     * @return    void
672
-     */
673
-    protected function _display_request_vars()
674
-    {
675
-        if ( ! WP_DEBUG) {
676
-            return;
677
-        }
678
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * _block_bots
692
-     * checks that the incoming request has either of the following set:
693
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
-     * then where you coming from man?
697
-     *
698
-     * @return boolean
699
-     */
700
-    private function _block_bots()
701
-    {
702
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
-            return true;
705
-        }
706
-        return false;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     *    _get_first_step
713
-     *  gets slug for first step in $_reg_steps_array
714
-     *
715
-     * @access    private
716
-     * @throws EE_Error
717
-     * @return    string
718
-     */
719
-    private function _get_first_step()
720
-    {
721
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     *    _load_and_instantiate_reg_steps
729
-     *  instantiates each reg step based on the loaded reg_steps array
730
-     *
731
-     * @access    private
732
-     * @throws EE_Error
733
-     * @return    bool
734
-     */
735
-    private function _load_and_instantiate_reg_steps()
736
-    {
737
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
-        // have reg_steps already been instantiated ?
739
-        if (
740
-            empty($this->checkout->reg_steps)
741
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
-        ) {
743
-            // if not, then loop through raw reg steps array
744
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
-                    return false;
747
-                }
748
-            }
749
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
-            // skip the registration_confirmation page ?
752
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
-                // just remove it from the reg steps array
754
-                $this->checkout->remove_reg_step('registration_confirmation', false);
755
-            } else if (
756
-                isset($this->checkout->reg_steps['registration_confirmation'])
757
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
-            ) {
759
-                // set the order to something big like 100
760
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
761
-            }
762
-            // filter the array for good luck
763
-            $this->checkout->reg_steps = apply_filters(
764
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
-                $this->checkout->reg_steps
766
-            );
767
-            // finally re-sort based on the reg step class order properties
768
-            $this->checkout->sort_reg_steps();
769
-        } else {
770
-            foreach ($this->checkout->reg_steps as $reg_step) {
771
-                // set all current step stati to FALSE
772
-                $reg_step->set_is_current_step(false);
773
-            }
774
-        }
775
-        if (empty($this->checkout->reg_steps)) {
776
-            EE_Error::add_error(
777
-                __('No Reg Steps were loaded..', 'event_espresso'),
778
-                __FILE__, __FUNCTION__, __LINE__
779
-            );
780
-            return false;
781
-        }
782
-        // make reg step details available to JS
783
-        $this->checkout->set_reg_step_JSON_info();
784
-        return true;
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     *     _load_and_instantiate_reg_step
791
-     *
792
-     * @access    private
793
-     * @param array $reg_step
794
-     * @param int   $order
795
-     * @return bool
796
-     */
797
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
-    {
799
-        // we need a file_path, class_name, and slug to add a reg step
800
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
-            if (
803
-                $this->checkout->reg_url_link
804
-                && $this->checkout->step !== $reg_step['slug']
805
-                && $reg_step['slug'] !== 'finalize_registration'
806
-                // normally at this point we would NOT load the reg step, but this filter can change that
807
-                && apply_filters(
808
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
-                    true,
810
-                    $reg_step,
811
-                    $this->checkout
812
-                )
813
-            ) {
814
-                return true;
815
-            }
816
-            // instantiate step class using file path and class name
817
-            $reg_step_obj = EE_Registry::instance()->load_file(
818
-                $reg_step['file_path'],
819
-                $reg_step['class_name'],
820
-                'class',
821
-                $this->checkout,
822
-                false
823
-            );
824
-            // did we gets the goods ?
825
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
-                // set reg step order based on config
827
-                $reg_step_obj->set_order($order);
828
-                // add instantiated reg step object to the master reg steps array
829
-                $this->checkout->add_reg_step($reg_step_obj);
830
-            } else {
831
-                EE_Error::add_error(
832
-                    __('The current step could not be set.', 'event_espresso'),
833
-                    __FILE__, __FUNCTION__, __LINE__
834
-                );
835
-                return false;
836
-            }
837
-        } else {
838
-            if (WP_DEBUG) {
839
-                EE_Error::add_error(
840
-                    sprintf(
841
-                        __(
842
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
843
-                            'event_espresso'
844
-                        ),
845
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
-                        '<ul>',
849
-                        '<li>',
850
-                        '</li>',
851
-                        '</ul>'
852
-                    ),
853
-                    __FILE__, __FUNCTION__, __LINE__
854
-                );
855
-            }
856
-            return false;
857
-        }
858
-        return true;
859
-    }
860
-
861
-
862
-    /**
863
-     * _verify_transaction_and_get_registrations
864
-     *
865
-     * @access private
866
-     * @return bool
867
-     * @throws InvalidDataTypeException
868
-     * @throws InvalidEntityException
869
-     * @throws EE_Error
870
-     */
871
-    private function _verify_transaction_and_get_registrations()
872
-    {
873
-        // was there already a valid transaction in the checkout from the session ?
874
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
-            // get transaction from db or session
876
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
-                ? $this->_get_transaction_and_cart_for_previous_visit()
878
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
879
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
-                EE_Error::add_error(
881
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
882
-                        'event_espresso'),
883
-                    __FILE__, __FUNCTION__, __LINE__
884
-                );
885
-                $this->checkout->transaction = EE_Transaction::new_instance();
886
-                // add some style and make it dance
887
-                $this->add_styles_and_scripts();
888
-                EED_Single_Page_Checkout::$_initialized = true;
889
-                return false;
890
-            }
891
-            // and the registrations for the transaction
892
-            $this->_get_registrations($this->checkout->transaction);
893
-        }
894
-        return true;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _get_transaction_and_cart_for_previous_visit
901
-     *
902
-     * @access private
903
-     * @return mixed EE_Transaction|NULL
904
-     */
905
-    private function _get_transaction_and_cart_for_previous_visit()
906
-    {
907
-        /** @var $TXN_model EEM_Transaction */
908
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
909
-        // because the reg_url_link is present in the request,
910
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
911
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
-        // verify transaction
913
-        if ($transaction instanceof EE_Transaction) {
914
-            // and get the cart that was used for that transaction
915
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
-            return $transaction;
917
-        }
918
-        EE_Error::add_error(
919
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
-            __FILE__, __FUNCTION__, __LINE__
921
-        );
922
-        return null;
923
-
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * _get_cart_for_transaction
930
-     *
931
-     * @access private
932
-     * @param EE_Transaction $transaction
933
-     * @return EE_Cart
934
-     */
935
-    private function _get_cart_for_transaction($transaction)
936
-    {
937
-        return $this->checkout->get_cart_for_transaction($transaction);
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * get_cart_for_transaction
944
-     *
945
-     * @access public
946
-     * @param EE_Transaction $transaction
947
-     * @return EE_Cart
948
-     */
949
-    public function get_cart_for_transaction(EE_Transaction $transaction)
950
-    {
951
-        return $this->checkout->get_cart_for_transaction($transaction);
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * _get_transaction_and_cart_for_current_session
958
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
-     *
960
-     * @access private
961
-     * @return EE_Transaction
962
-     * @throws EE_Error
963
-     */
964
-    private function _get_cart_for_current_session_and_setup_new_transaction()
965
-    {
966
-        //  if there's no transaction, then this is the FIRST visit to SPCO
967
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
969
-        // and then create a new transaction
970
-        $transaction = $this->_initialize_transaction();
971
-        // verify transaction
972
-        if ($transaction instanceof EE_Transaction) {
973
-            // save it so that we have an ID for other objects to use
974
-            $transaction->save();
975
-            // and save TXN data to the cart
976
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
-        } else {
978
-            EE_Error::add_error(
979
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
980
-                __FILE__, __FUNCTION__, __LINE__
981
-            );
982
-        }
983
-        return $transaction;
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
-     *
991
-     * @access private
992
-     * @return mixed EE_Transaction|NULL
993
-     */
994
-    private function _initialize_transaction()
995
-    {
996
-        try {
997
-            // ensure cart totals have been calculated
998
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
-            // grab the cart grand total
1000
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1001
-            // create new TXN
1002
-            $transaction = EE_Transaction::new_instance(
1003
-                array(
1004
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
-                    'TXN_paid'      => 0,
1007
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1008
-                )
1009
-            );
1010
-            // save it so that we have an ID for other objects to use
1011
-            $transaction->save();
1012
-            // set cron job for following up on TXNs after their session has expired
1013
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1014
-                EE_Registry::instance()->SSN->expiration() + 1,
1015
-                $transaction->ID()
1016
-            );
1017
-            return $transaction;
1018
-        } catch (Exception $e) {
1019
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
-        }
1021
-        return null;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * _get_registrations
1027
-     *
1028
-     * @access private
1029
-     * @param EE_Transaction $transaction
1030
-     * @return void
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidEntityException
1033
-     * @throws EE_Error
1034
-     */
1035
-    private function _get_registrations(EE_Transaction $transaction)
1036
-    {
1037
-        // first step: grab the registrants  { : o
1038
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
-        $this->checkout->total_ticket_count = count($registrations);
1040
-        // verify registrations have been set
1041
-        if (empty($registrations)) {
1042
-            // if no cached registrations, then check the db
1043
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
-            // still nothing ? well as long as this isn't a revisit
1045
-            if (empty($registrations) && ! $this->checkout->revisit) {
1046
-                // generate new registrations from scratch
1047
-                $registrations = $this->_initialize_registrations($transaction);
1048
-            }
1049
-        }
1050
-        // sort by their original registration order
1051
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
-        // then loop thru the array
1053
-        foreach ($registrations as $registration) {
1054
-            // verify each registration
1055
-            if ($registration instanceof EE_Registration) {
1056
-                // we display all attendee info for the primary registrant
1057
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
-                    && $registration->is_primary_registrant()
1059
-                ) {
1060
-                    $this->checkout->primary_revisit = true;
1061
-                    break;
1062
-                }
1063
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
-                    // but hide info if it doesn't belong to you
1065
-                    $transaction->clear_cache('Registration', $registration->ID());
1066
-                    $this->checkout->total_ticket_count--;
1067
-                }
1068
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1069
-            }
1070
-        }
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
-     *
1077
-     * @access private
1078
-     * @param EE_Transaction $transaction
1079
-     * @return    array
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidEntityException
1082
-     * @throws EE_Error
1083
-     */
1084
-    private function _initialize_registrations(EE_Transaction $transaction)
1085
-    {
1086
-        $att_nmbr = 0;
1087
-        $registrations = array();
1088
-        if ($transaction instanceof EE_Transaction) {
1089
-            /** @type EE_Registration_Processor $registration_processor */
1090
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
-            // now let's add the cart items to the $transaction
1093
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
-                //do the following for each ticket of this type they selected
1095
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
-                    $att_nmbr++;
1097
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1099
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
-                        array(
1101
-                            $transaction,
1102
-                            $line_item,
1103
-                            $att_nmbr,
1104
-                            $this->checkout->total_ticket_count,
1105
-                        )
1106
-                    );
1107
-                    // override capabilities for frontend registrations
1108
-                    if ( ! is_admin()) {
1109
-                        $CreateRegistrationCommand->setCapCheck(
1110
-                            new PublicCapabilities('', 'create_new_registration')
1111
-                        );
1112
-                    }
1113
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
-                    if ( ! $registration instanceof EE_Registration) {
1115
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1116
-                    }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1118
-                }
1119
-            }
1120
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
-        }
1122
-        return $registrations;
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * sorts registrations by REG_count
1129
-     *
1130
-     * @access public
1131
-     * @param EE_Registration $reg_A
1132
-     * @param EE_Registration $reg_B
1133
-     * @return int
1134
-     */
1135
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
-    {
1137
-        // this shouldn't ever happen within the same TXN, but oh well
1138
-        if ($reg_A->count() === $reg_B->count()) {
1139
-            return 0;
1140
-        }
1141
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
-    }
1143
-
1144
-
1145
-
1146
-    /**
1147
-     *    _final_verifications
1148
-     * just makes sure that everything is set up correctly before proceeding
1149
-     *
1150
-     * @access    private
1151
-     * @return    bool
1152
-     * @throws EE_Error
1153
-     */
1154
-    private function _final_verifications()
1155
-    {
1156
-        // filter checkout
1157
-        $this->checkout = apply_filters(
1158
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
-            $this->checkout
1160
-        );
1161
-        //verify that current step is still set correctly
1162
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
-            EE_Error::add_error(
1164
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1165
-                __FILE__,
1166
-                __FUNCTION__,
1167
-                __LINE__
1168
-            );
1169
-            return false;
1170
-        }
1171
-        // if returning to SPCO, then verify that primary registrant is set
1172
-        if ( ! empty($this->checkout->reg_url_link)) {
1173
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1174
-            if ( ! $valid_registrant instanceof EE_Registration) {
1175
-                EE_Error::add_error(
1176
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1177
-                    __FILE__,
1178
-                    __FUNCTION__,
1179
-                    __LINE__
1180
-                );
1181
-                return false;
1182
-            }
1183
-            $valid_registrant = null;
1184
-            foreach (
1185
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
-            ) {
1187
-                if (
1188
-                    $registration instanceof EE_Registration
1189
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1190
-                ) {
1191
-                    $valid_registrant = $registration;
1192
-                }
1193
-            }
1194
-            if ( ! $valid_registrant instanceof EE_Registration) {
1195
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
-                    // clear the session, mark the checkout as unverified, and try again
1198
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
-                    EED_Single_Page_Checkout::$_initialized = false;
1200
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1201
-                    $this->_initialize();
1202
-                    EE_Error::reset_notices();
1203
-                    return false;
1204
-                }
1205
-                EE_Error::add_error(
1206
-                    __(
1207
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1208
-                        'event_espresso'
1209
-                    ),
1210
-                    __FILE__,
1211
-                    __FUNCTION__,
1212
-                    __LINE__
1213
-                );
1214
-                return false;
1215
-            }
1216
-        }
1217
-        // now that things have been kinda sufficiently verified,
1218
-        // let's add the checkout to the session so that it's available to other systems
1219
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
-        return true;
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     *    _initialize_reg_steps
1227
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
-     *
1230
-     * @access    private
1231
-     * @param bool $reinitializing
1232
-     * @throws EE_Error
1233
-     */
1234
-    private function _initialize_reg_steps($reinitializing = false)
1235
-    {
1236
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
-        foreach ($this->checkout->reg_steps as $reg_step) {
1239
-            if ( ! $reg_step->initialize_reg_step()) {
1240
-                // if not initialized then maybe this step is being removed...
1241
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
-                    // if it was the current step, then we need to start over here
1243
-                    $this->_initialize_reg_steps(true);
1244
-                    return;
1245
-                }
1246
-                continue;
1247
-            }
1248
-            // add css and JS for current step
1249
-            $reg_step->enqueue_styles_and_scripts();
1250
-            // i18n
1251
-            $reg_step->translate_js_strings();
1252
-            if ($reg_step->is_current_step()) {
1253
-                // the text that appears on the reg step form submit button
1254
-                $reg_step->set_submit_button_text();
1255
-            }
1256
-        }
1257
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
-        do_action(
1259
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
-            $this->checkout->current_step
1261
-        );
1262
-    }
1263
-
1264
-
1265
-
1266
-    /**
1267
-     * _check_form_submission
1268
-     *
1269
-     * @access private
1270
-     * @return boolean
1271
-     */
1272
-    private function _check_form_submission()
1273
-    {
1274
-        //does this request require the reg form to be generated ?
1275
-        if ($this->checkout->generate_reg_form) {
1276
-            // ever heard that song by Blue Rodeo ?
1277
-            try {
1278
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
-                // if not displaying a form, then check for form submission
1280
-                if (
1281
-                    $this->checkout->process_form_submission
1282
-                    && $this->checkout->current_step->reg_form->was_submitted()
1283
-                ) {
1284
-                    // clear out any old data in case this step is being run again
1285
-                    $this->checkout->current_step->set_valid_data(array());
1286
-                    // capture submitted form data
1287
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1288
-                        apply_filters(
1289
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
-                            EE_Registry::instance()->REQ->params(),
1291
-                            $this->checkout
1292
-                        )
1293
-                    );
1294
-                    // validate submitted form data
1295
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
-                        // thou shall not pass !!!
1297
-                        $this->checkout->continue_reg = false;
1298
-                        // any form validation errors?
1299
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
-                            $submission_error_messages = array();
1301
-                            // bad, bad, bad registrant
1302
-                            foreach (
1303
-                                $this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1304
-                                as $validation_error
1305
-                            ) {
1306
-                                if ($validation_error instanceof EE_Validation_Error) {
1307
-                                    $submission_error_messages[] = sprintf(
1308
-                                        __('%s : %s', 'event_espresso'),
1309
-                                        $validation_error->get_form_section()->html_label_text(),
1310
-                                        $validation_error->getMessage()
1311
-                                    );
1312
-                                }
1313
-                            }
1314
-                            EE_Error::add_error(
1315
-                                implode('<br />', $submission_error_messages),
1316
-                                __FILE__, __FUNCTION__, __LINE__
1317
-                            );
1318
-                        }
1319
-                        // well not really... what will happen is
1320
-                        // we'll just get redirected back to redo the current step
1321
-                        $this->go_to_next_step();
1322
-                        return false;
1323
-                    }
1324
-                }
1325
-            } catch (EE_Error $e) {
1326
-                $e->get_error();
1327
-            }
1328
-        }
1329
-        return true;
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * _process_action
1336
-     *
1337
-     * @access private
1338
-     * @return void
1339
-     * @throws EE_Error
1340
-     */
1341
-    private function _process_form_action()
1342
-    {
1343
-        // what cha wanna do?
1344
-        switch ($this->checkout->action) {
1345
-            // AJAX next step reg form
1346
-            case 'display_spco_reg_step' :
1347
-                $this->checkout->redirect = false;
1348
-                if (EE_Registry::instance()->REQ->ajax) {
1349
-                    $this->checkout->json_response->set_reg_step_html(
1350
-                        $this->checkout->current_step->display_reg_form()
1351
-                    );
1352
-                }
1353
-                break;
1354
-            default :
1355
-                // meh... do one of those other steps first
1356
-                if (
1357
-                    ! empty($this->checkout->action)
1358
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1359
-                ) {
1360
-                    // dynamically creates hook point like:
1361
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1362
-                    do_action(
1363
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1364
-                        $this->checkout->current_step
1365
-                    );
1366
-                    // call action on current step
1367
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1368
-                        // good registrant, you get to proceed
1369
-                        if (
1370
-                            $this->checkout->current_step->success_message() !== ''
1371
-                            && apply_filters(
1372
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1373
-                                false
1374
-                            )
1375
-                        ) {
1376
-                            EE_Error::add_success(
1377
-                                $this->checkout->current_step->success_message()
1378
-                                . '<br />' . $this->checkout->next_step->_instructions()
1379
-                            );
1380
-                        }
1381
-                        // pack it up, pack it in...
1382
-                        $this->_setup_redirect();
1383
-                    }
1384
-                    // dynamically creates hook point like:
1385
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1386
-                    do_action(
1387
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1388
-                        $this->checkout->current_step
1389
-                    );
1390
-                } else {
1391
-                    EE_Error::add_error(
1392
-                        sprintf(
1393
-                            __(
1394
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1395
-                                'event_espresso'
1396
-                            ),
1397
-                            $this->checkout->action,
1398
-                            $this->checkout->current_step->name()
1399
-                        ),
1400
-                        __FILE__,
1401
-                        __FUNCTION__,
1402
-                        __LINE__
1403
-                    );
1404
-                }
1405
-            // end default
1406
-        }
1407
-        // store our progress so far
1408
-        $this->checkout->stash_transaction_and_checkout();
1409
-        // advance to the next step! If you pass GO, collect $200
1410
-        $this->go_to_next_step();
1411
-    }
1412
-
1413
-
1414
-
1415
-    /**
1416
-     *        add_styles_and_scripts
1417
-     *
1418
-     * @access        public
1419
-     * @return        void
1420
-     */
1421
-    public function add_styles_and_scripts()
1422
-    {
1423
-        // i18n
1424
-        $this->translate_js_strings();
1425
-        if ($this->checkout->admin_request) {
1426
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1427
-        } else {
1428
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1429
-        }
1430
-    }
1431
-
1432
-
1433
-
1434
-    /**
1435
-     *        translate_js_strings
1436
-     *
1437
-     * @access        public
1438
-     * @return        void
1439
-     */
1440
-    public function translate_js_strings()
1441
-    {
1442
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1443
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1444
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1445
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1446
-            'event_espresso'
1447
-        );
1448
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1449
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1450
-            'event_espresso'
1451
-        );
1452
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1453
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1454
-            'event_espresso'
1455
-        );
1456
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1457
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1458
-            'event_espresso'
1459
-        );
1460
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1461
-            'This registration step could not be completed. Please refresh the page and try again.',
1462
-            'event_espresso'
1463
-        );
1464
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1465
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1466
-            'event_espresso'
1467
-        );
1468
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1469
-            __(
1470
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1471
-                'event_espresso'
1472
-            ),
1473
-            '<br/>',
1474
-            '<br/>'
1475
-        );
1476
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1477
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1478
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1479
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1480
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1481
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1482
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1483
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1484
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1485
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1486
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1487
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1488
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1489
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1490
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1491
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1492
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1493
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1494
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1495
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1496
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1497
-            true
1498
-        );
1499
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1500
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1501
-        );
1502
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1503
-            'M d, Y H:i:s',
1504
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1505
-        );
1506
-    }
1507
-
1508
-
1509
-
1510
-    /**
1511
-     *    enqueue_styles_and_scripts
1512
-     *
1513
-     * @access        public
1514
-     * @return        void
1515
-     * @throws EE_Error
1516
-     */
1517
-    public function enqueue_styles_and_scripts()
1518
-    {
1519
-        // load css
1520
-        wp_register_style(
1521
-            'single_page_checkout',
1522
-            SPCO_CSS_URL . 'single_page_checkout.css',
1523
-            array('espresso_default'),
1524
-            EVENT_ESPRESSO_VERSION
1525
-        );
1526
-        wp_enqueue_style('single_page_checkout');
1527
-        // load JS
1528
-        wp_register_script(
1529
-            'jquery_plugin',
1530
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1531
-            array('jquery'),
1532
-            '1.0.1',
1533
-            true
1534
-        );
1535
-        wp_register_script(
1536
-            'jquery_countdown',
1537
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1538
-            array('jquery_plugin'),
1539
-            '2.0.2',
1540
-            true
1541
-        );
1542
-        wp_register_script(
1543
-            'single_page_checkout',
1544
-            SPCO_JS_URL . 'single_page_checkout.js',
1545
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1546
-            EVENT_ESPRESSO_VERSION,
1547
-            true
1548
-        );
1549
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1550
-            $this->checkout->registration_form->enqueue_js();
1551
-        }
1552
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1553
-            $this->checkout->current_step->reg_form->enqueue_js();
1554
-        }
1555
-        wp_enqueue_script('single_page_checkout');
1556
-        /**
1557
-         * global action hook for enqueueing styles and scripts with
1558
-         * spco calls.
1559
-         */
1560
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1561
-        /**
1562
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1563
-         * The hook will end up being something like:
1564
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1565
-         */
1566
-        do_action(
1567
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1568
-            $this
1569
-        );
1570
-    }
1571
-
1572
-
1573
-
1574
-    /**
1575
-     *    display the Registration Single Page Checkout Form
1576
-     *
1577
-     * @access    private
1578
-     * @return    void
1579
-     * @throws EE_Error
1580
-     */
1581
-    private function _display_spco_reg_form()
1582
-    {
1583
-        // if registering via the admin, just display the reg form for the current step
1584
-        if ($this->checkout->admin_request) {
1585
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1586
-        } else {
1587
-            // add powered by EE msg
1588
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1589
-            $empty_cart = count(
1590
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1591
-            ) < 1;
1592
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1593
-            $cookies_not_set_msg = '';
1594
-            if ($empty_cart) {
1595
-                $cookies_not_set_msg = apply_filters(
1596
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1597
-                    sprintf(
1598
-                        __(
1599
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1600
-                            'event_espresso'
1601
-                        ),
1602
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1603
-                        '</div>',
1604
-                        '<h6 class="important-notice">',
1605
-                        '</h6>',
1606
-                        '<p>',
1607
-                        '</p>',
1608
-                        '<br />',
1609
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1610
-                        '</a>'
1611
-                    )
1612
-                );
1613
-            }
1614
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1615
-                array(
1616
-                    'name'            => 'single-page-checkout',
1617
-                    'html_id'         => 'ee-single-page-checkout-dv',
1618
-                    'layout_strategy' =>
1619
-                        new EE_Template_Layout(
1620
-                            array(
1621
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1622
-                                'template_args'        => array(
1623
-                                    'empty_cart'              => $empty_cart,
1624
-                                    'revisit'                 => $this->checkout->revisit,
1625
-                                    'reg_steps'               => $this->checkout->reg_steps,
1626
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1627
-                                        ? $this->checkout->next_step->slug()
1628
-                                        : '',
1629
-                                    'empty_msg'               => apply_filters(
1630
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1631
-                                        sprintf(
1632
-                                            __(
1633
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1634
-                                                'event_espresso'
1635
-                                            ),
1636
-                                            '<a href="'
1637
-                                            . get_post_type_archive_link('espresso_events')
1638
-                                            . '" title="',
1639
-                                            '">',
1640
-                                            '</a>'
1641
-                                        )
1642
-                                    ),
1643
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1644
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1645
-                                    'session_expiration'      => gmdate(
1646
-                                        'M d, Y H:i:s',
1647
-                                        EE_Registry::instance()->SSN->expiration()
1648
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1649
-                                    ),
1650
-                                ),
1651
-                            )
1652
-                        ),
1653
-                )
1654
-            );
1655
-            // load template and add to output sent that gets filtered into the_content()
1656
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1657
-        }
1658
-    }
1659
-
1660
-
1661
-
1662
-    /**
1663
-     *    add_extra_finalize_registration_inputs
1664
-     *
1665
-     * @access    public
1666
-     * @param $next_step
1667
-     * @internal  param string $label
1668
-     * @return void
1669
-     */
1670
-    public function add_extra_finalize_registration_inputs($next_step)
1671
-    {
1672
-        if ($next_step === 'finalize_registration') {
1673
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1674
-        }
1675
-    }
1676
-
1677
-
1678
-
1679
-    /**
1680
-     *    display_registration_footer
1681
-     *
1682
-     * @access    public
1683
-     * @return    string
1684
-     */
1685
-    public static function display_registration_footer()
1686
-    {
1687
-        if (
1688
-        apply_filters(
1689
-            'FHEE__EE_Front__Controller__show_reg_footer',
1690
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1691
-        )
1692
-        ) {
1693
-            add_filter(
1694
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1695
-                function ($url) {
1696
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1697
-                }
1698
-            );
1699
-            echo apply_filters(
1700
-                'FHEE__EE_Front_Controller__display_registration_footer',
1701
-                \EEH_Template::powered_by_event_espresso(
1702
-                    '',
1703
-                    'espresso-registration-footer-dv',
1704
-                    array('utm_content' => 'registration_checkout')
1705
-                )
1706
-            );
1707
-        }
1708
-        return '';
1709
-    }
1710
-
1711
-
1712
-
1713
-    /**
1714
-     *    unlock_transaction
1715
-     *
1716
-     * @access    public
1717
-     * @return    void
1718
-     * @throws EE_Error
1719
-     */
1720
-    public function unlock_transaction()
1721
-    {
1722
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1723
-            $this->checkout->transaction->unlock();
1724
-        }
1725
-    }
1726
-
1727
-
1728
-
1729
-    /**
1730
-     *        _setup_redirect
1731
-     *
1732
-     * @access    private
1733
-     * @return void
1734
-     */
1735
-    private function _setup_redirect()
1736
-    {
1737
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1738
-            $this->checkout->redirect = true;
1739
-            if (empty($this->checkout->redirect_url)) {
1740
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1741
-            }
1742
-            $this->checkout->redirect_url = apply_filters(
1743
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1744
-                $this->checkout->redirect_url,
1745
-                $this->checkout
1746
-            );
1747
-        }
1748
-    }
1749
-
1750
-
1751
-
1752
-    /**
1753
-     *   handle ajax message responses and redirects
1754
-     *
1755
-     * @access public
1756
-     * @return void
1757
-     * @throws EE_Error
1758
-     */
1759
-    public function go_to_next_step()
1760
-    {
1761
-        if (EE_Registry::instance()->REQ->ajax) {
1762
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1763
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1764
-        }
1765
-        $this->unlock_transaction();
1766
-        // just return for these conditions
1767
-        if (
1768
-            $this->checkout->admin_request
1769
-            || $this->checkout->action === 'redirect_form'
1770
-            || $this->checkout->action === 'update_checkout'
1771
-        ) {
1772
-            return;
1773
-        }
1774
-        // AJAX response
1775
-        $this->_handle_json_response();
1776
-        // redirect to next step or the Thank You page
1777
-        $this->_handle_html_redirects();
1778
-        // hmmm... must be something wrong, so let's just display the form again !
1779
-        $this->_display_spco_reg_form();
1780
-    }
1781
-
1782
-
1783
-
1784
-    /**
1785
-     *   _handle_json_response
1786
-     *
1787
-     * @access protected
1788
-     * @return void
1789
-     */
1790
-    protected function _handle_json_response()
1791
-    {
1792
-        // if this is an ajax request
1793
-        if (EE_Registry::instance()->REQ->ajax) {
1794
-            // DEBUG LOG
1795
-            //$this->checkout->log(
1796
-            //	__CLASS__, __FUNCTION__, __LINE__,
1797
-            //	array(
1798
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1799
-            //		'redirect'                   => $this->checkout->redirect,
1800
-            //		'continue_reg'               => $this->checkout->continue_reg,
1801
-            //	)
1802
-            //);
1803
-            $this->checkout->json_response->set_registration_time_limit(
1804
-                $this->checkout->get_registration_time_limit()
1805
-            );
1806
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1807
-            // just send the ajax (
1808
-            $json_response = apply_filters(
1809
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1810
-                $this->checkout->json_response
1811
-            );
1812
-            echo $json_response;
1813
-            exit();
1814
-        }
1815
-    }
1816
-
1817
-
1818
-
1819
-    /**
1820
-     *   _handle_redirects
1821
-     *
1822
-     * @access protected
1823
-     * @return void
1824
-     */
1825
-    protected function _handle_html_redirects()
1826
-    {
1827
-        // going somewhere ?
1828
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1829
-            // store notices in a transient
1830
-            EE_Error::get_notices(false, true, true);
1831
-            // DEBUG LOG
1832
-            //$this->checkout->log(
1833
-            //	__CLASS__, __FUNCTION__, __LINE__,
1834
-            //	array(
1835
-            //		'headers_sent' => headers_sent(),
1836
-            //		'redirect_url'     => $this->checkout->redirect_url,
1837
-            //		'headers_list'    => headers_list(),
1838
-            //	)
1839
-            //);
1840
-            wp_safe_redirect($this->checkout->redirect_url);
1841
-            exit();
1842
-        }
1843
-    }
1844
-
1845
-
1846
-
1847
-    /**
1848
-     *   set_checkout_anchor
1849
-     *
1850
-     * @access public
1851
-     * @return void
1852
-     */
1853
-    public function set_checkout_anchor()
1854
-    {
1855
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1856
-    }
1857
-
1858
-    /**
1859
-     *    getRegistrationExpirationNotice
1860
-     *
1861
-     * @since $VID:$
1862
-     * @access    public
1863
-     * @return    string
1864
-     */
1865
-    public static function getRegistrationExpirationNotice()
1866
-    {
1867
-        return sprintf(
1868
-            __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1869
-                'event_espresso'),
1870
-            '<h4 class="important-notice">',
1871
-            '</h4>',
1872
-            '<br />',
1873
-            '<p>',
1874
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1875
-            '">',
1876
-            '</a>',
1877
-            '</p>'
1878
-        );
1879
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * load_reg_steps
242
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
+	 *
244
+	 * @access    private
245
+	 * @throws EE_Error
246
+	 */
247
+	public static function load_reg_steps()
248
+	{
249
+		static $reg_steps_loaded = false;
250
+		if ($reg_steps_loaded) {
251
+			return;
252
+		}
253
+		// filter list of reg_steps
254
+		$reg_steps_to_load = (array)apply_filters(
255
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
+			EED_Single_Page_Checkout::get_reg_steps()
257
+		);
258
+		// sort by key (order)
259
+		ksort($reg_steps_to_load);
260
+		// loop through folders
261
+		foreach ($reg_steps_to_load as $order => $reg_step) {
262
+			// we need a
263
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
+				// copy over to the reg_steps_array
265
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
+				// register custom key route for each reg step
267
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
+				EE_Config::register_route(
269
+					$reg_step['slug'],
270
+					'EED_Single_Page_Checkout',
271
+					'run',
272
+					'step'
273
+				);
274
+				// add AJAX or other hooks
275
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
+					// setup autoloaders if necessary
277
+					if ( ! class_exists($reg_step['class_name'])) {
278
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
+							$reg_step['file_path'],
280
+							true
281
+						);
282
+					}
283
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
+					}
286
+				}
287
+			}
288
+		}
289
+		$reg_steps_loaded = true;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 *    get_reg_steps
296
+	 *
297
+	 * @access    public
298
+	 * @return    array
299
+	 */
300
+	public static function get_reg_steps()
301
+	{
302
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
+		if (empty($reg_steps)) {
304
+			$reg_steps = array(
305
+				10  => array(
306
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
+					'slug'       => 'attendee_information',
309
+					'has_hooks'  => false,
310
+				),
311
+				20  => array(
312
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
+					'slug'       => 'registration_confirmation',
315
+					'has_hooks'  => false,
316
+				),
317
+				30  => array(
318
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
+					'slug'       => 'payment_options',
321
+					'has_hooks'  => true,
322
+				),
323
+				999 => array(
324
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
+					'slug'       => 'finalize_registration',
327
+					'has_hooks'  => false,
328
+				),
329
+			);
330
+		}
331
+		return $reg_steps;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 *    registration_checkout_for_admin
338
+	 *
339
+	 * @access    public
340
+	 * @return    string
341
+	 * @throws EE_Error
342
+	 */
343
+	public static function registration_checkout_for_admin()
344
+	{
345
+		EED_Single_Page_Checkout::load_request_handler();
346
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
349
+		EED_Single_Page_Checkout::instance()->_initialize();
350
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
+		return EE_Registry::instance()->REQ->get_output();
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * process_registration_from_admin
358
+	 *
359
+	 * @access public
360
+	 * @return \EE_Transaction
361
+	 * @throws EE_Error
362
+	 */
363
+	public static function process_registration_from_admin()
364
+	{
365
+		EED_Single_Page_Checkout::load_request_handler();
366
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
369
+		EED_Single_Page_Checkout::instance()->_initialize();
370
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
+				if ($final_reg_step->process_reg_step()) {
375
+					$final_reg_step->set_completed();
376
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
+				}
379
+			}
380
+		}
381
+		return null;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 *    run
388
+	 *
389
+	 * @access    public
390
+	 * @param WP_Query $WP_Query
391
+	 * @return    void
392
+	 * @throws EE_Error
393
+	 */
394
+	public function run($WP_Query)
395
+	{
396
+		if (
397
+			$WP_Query instanceof WP_Query
398
+			&& $WP_Query->is_main_query()
399
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
+			&& $this->_is_reg_checkout()
401
+		) {
402
+			$this->_initialize();
403
+		}
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * determines whether current url matches reg page url
410
+	 *
411
+	 * @return bool
412
+	 */
413
+	protected function _is_reg_checkout()
414
+	{
415
+		// get current permalink for reg page without any extra query args
416
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
+		// get request URI for current request, but without the scheme or host
418
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
+		$current_request_uri = html_entity_decode($current_request_uri);
420
+		// get array of query args from the current request URI
421
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
422
+		// grab page id if it is set
423
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
+		// and remove the page id from the query args (we will re-add it later)
425
+		unset($query_args['page_id']);
426
+		// now strip all query args from current request URI
427
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
+		// and re-add the page id if it was set
429
+		if ($page_id) {
430
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
+		}
432
+		// remove slashes and ?
433
+		$current_request_uri = trim($current_request_uri, '?/');
434
+		// is current request URI part of the known full reg page URL ?
435
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 * @param WP_Query $wp_query
442
+	 * @return    void
443
+	 * @throws EE_Error
444
+	 */
445
+	public static function init($wp_query)
446
+	{
447
+		EED_Single_Page_Checkout::instance()->run($wp_query);
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 *    _initialize - initial module setup
454
+	 *
455
+	 * @access    private
456
+	 * @throws EE_Error
457
+	 * @return    void
458
+	 */
459
+	private function _initialize()
460
+	{
461
+		// ensure SPCO doesn't run twice
462
+		if (EED_Single_Page_Checkout::$_initialized) {
463
+			return;
464
+		}
465
+		try {
466
+			EED_Single_Page_Checkout::load_reg_steps();
467
+			$this->_verify_session();
468
+			// setup the EE_Checkout object
469
+			$this->checkout = $this->_initialize_checkout();
470
+			// filter checkout
471
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
+			// get the $_GET
473
+			$this->_get_request_vars();
474
+			if ($this->_block_bots()) {
475
+				return;
476
+			}
477
+			// filter continue_reg
478
+			$this->checkout->continue_reg = apply_filters(
479
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
+				true,
481
+				$this->checkout
482
+			);
483
+			// load the reg steps array
484
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
485
+				EED_Single_Page_Checkout::$_initialized = true;
486
+				return;
487
+			}
488
+			// set the current step
489
+			$this->checkout->set_current_step($this->checkout->step);
490
+			// and the next step
491
+			$this->checkout->set_next_step();
492
+			// verify that everything has been setup correctly
493
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
+				EED_Single_Page_Checkout::$_initialized = true;
495
+				return;
496
+			}
497
+			// lock the transaction
498
+			$this->checkout->transaction->lock();
499
+			// make sure all of our cached objects are added to their respective model entity mappers
500
+			$this->checkout->refresh_all_entities();
501
+			// set amount owing
502
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
+			// initialize each reg step, which gives them the chance to potentially alter the process
504
+			$this->_initialize_reg_steps();
505
+			// DEBUG LOG
506
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
+			// get reg form
508
+			if( ! $this->_check_form_submission()) {
509
+				EED_Single_Page_Checkout::$_initialized = true;
510
+				return;
511
+			}
512
+			// checkout the action!!!
513
+			$this->_process_form_action();
514
+			// add some style and make it dance
515
+			$this->add_styles_and_scripts();
516
+			// kk... SPCO has successfully run
517
+			EED_Single_Page_Checkout::$_initialized = true;
518
+			// set no cache headers and constants
519
+			EE_System::do_not_cache();
520
+			// add anchor
521
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
+			// remove transaction lock
523
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
+		} catch (Exception $e) {
525
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
+		}
527
+	}
528
+
529
+
530
+
531
+	/**
532
+	 *    _verify_session
533
+	 * checks that the session is valid and not expired
534
+	 *
535
+	 * @access    private
536
+	 * @throws EE_Error
537
+	 */
538
+	private function _verify_session()
539
+	{
540
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
+		}
543
+		$clear_session_requested = filter_var(
544
+			EE_Registry::instance()->REQ->get('clear_session', false),
545
+			FILTER_VALIDATE_BOOLEAN
546
+		);
547
+		// is session still valid ?
548
+		if ($clear_session_requested
549
+			|| ( EE_Registry::instance()->SSN->expired()
550
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
+			)
552
+		) {
553
+			$this->checkout = new EE_Checkout();
554
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
+			// EE_Registry::instance()->SSN->reset_cart();
556
+			// EE_Registry::instance()->SSN->reset_checkout();
557
+			// EE_Registry::instance()->SSN->reset_transaction();
558
+			if (! $clear_session_requested) {
559
+				EE_Error::add_attention(
560
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
+					__FILE__, __FUNCTION__, __LINE__
562
+				);
563
+			}
564
+			// EE_Registry::instance()->SSN->reset_expired();
565
+		}
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 *    _initialize_checkout
572
+	 * loads and instantiates EE_Checkout
573
+	 *
574
+	 * @access    private
575
+	 * @throws EE_Error
576
+	 * @return EE_Checkout
577
+	 */
578
+	private function _initialize_checkout()
579
+	{
580
+		// look in session for existing checkout
581
+		/** @type EE_Checkout $checkout */
582
+		$checkout = EE_Registry::instance()->SSN->checkout();
583
+		// verify
584
+		if ( ! $checkout instanceof EE_Checkout) {
585
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
586
+			$checkout = EE_Registry::instance()->load_file(
587
+				SPCO_INC_PATH,
588
+				'EE_Checkout',
589
+				'class', array(),
590
+				false
591
+			);
592
+		} else {
593
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
+				$this->unlock_transaction();
595
+				wp_safe_redirect($checkout->redirect_url);
596
+				exit();
597
+			}
598
+		}
599
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
+		// verify again
601
+		if ( ! $checkout instanceof EE_Checkout) {
602
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
+		}
604
+		// reset anything that needs a clean slate for each request
605
+		$checkout->reset_for_current_request();
606
+		return $checkout;
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 *    _get_request_vars
613
+	 *
614
+	 * @access    private
615
+	 * @return    void
616
+	 * @throws EE_Error
617
+	 */
618
+	private function _get_request_vars()
619
+	{
620
+		// load classes
621
+		EED_Single_Page_Checkout::load_request_handler();
622
+		//make sure this request is marked as belonging to EE
623
+		EE_Registry::instance()->REQ->set_espresso_page(true);
624
+		// which step is being requested ?
625
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
+		// which step is being edited ?
627
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
+		// and what we're doing on the current step
629
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
+		// timestamp
631
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
+		// returning to edit ?
633
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
+		// add reg url link to registration query params
635
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
+		}
638
+		// or some other kind of revisit ?
639
+		$this->checkout->revisit = filter_var(
640
+			EE_Registry::instance()->REQ->get('revisit', false),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to generate a reg form for this request
644
+		$this->checkout->generate_reg_form = filter_var(
645
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
+			FILTER_VALIDATE_BOOLEAN
647
+		);
648
+		// and whether or not to process a reg form submission for this request
649
+		$this->checkout->process_form_submission = filter_var(
650
+			EE_Registry::instance()->REQ->get(
651
+				'process_form_submission',
652
+				$this->checkout->action === 'process_reg_step'
653
+			),
654
+			FILTER_VALIDATE_BOOLEAN
655
+		);
656
+		$this->checkout->process_form_submission = filter_var(
657
+			$this->checkout->action !== 'display_spco_reg_step'
658
+				? $this->checkout->process_form_submission
659
+				: false,
660
+			FILTER_VALIDATE_BOOLEAN
661
+		);
662
+		// $this->_display_request_vars();
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 *  _display_request_vars
669
+	 *
670
+	 * @access    protected
671
+	 * @return    void
672
+	 */
673
+	protected function _display_request_vars()
674
+	{
675
+		if ( ! WP_DEBUG) {
676
+			return;
677
+		}
678
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * _block_bots
692
+	 * checks that the incoming request has either of the following set:
693
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
+	 * then where you coming from man?
697
+	 *
698
+	 * @return boolean
699
+	 */
700
+	private function _block_bots()
701
+	{
702
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
+			return true;
705
+		}
706
+		return false;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 *    _get_first_step
713
+	 *  gets slug for first step in $_reg_steps_array
714
+	 *
715
+	 * @access    private
716
+	 * @throws EE_Error
717
+	 * @return    string
718
+	 */
719
+	private function _get_first_step()
720
+	{
721
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 *    _load_and_instantiate_reg_steps
729
+	 *  instantiates each reg step based on the loaded reg_steps array
730
+	 *
731
+	 * @access    private
732
+	 * @throws EE_Error
733
+	 * @return    bool
734
+	 */
735
+	private function _load_and_instantiate_reg_steps()
736
+	{
737
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
+		// have reg_steps already been instantiated ?
739
+		if (
740
+			empty($this->checkout->reg_steps)
741
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
+		) {
743
+			// if not, then loop through raw reg steps array
744
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
+					return false;
747
+				}
748
+			}
749
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
+			// skip the registration_confirmation page ?
752
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
+				// just remove it from the reg steps array
754
+				$this->checkout->remove_reg_step('registration_confirmation', false);
755
+			} else if (
756
+				isset($this->checkout->reg_steps['registration_confirmation'])
757
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
+			) {
759
+				// set the order to something big like 100
760
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
761
+			}
762
+			// filter the array for good luck
763
+			$this->checkout->reg_steps = apply_filters(
764
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
+				$this->checkout->reg_steps
766
+			);
767
+			// finally re-sort based on the reg step class order properties
768
+			$this->checkout->sort_reg_steps();
769
+		} else {
770
+			foreach ($this->checkout->reg_steps as $reg_step) {
771
+				// set all current step stati to FALSE
772
+				$reg_step->set_is_current_step(false);
773
+			}
774
+		}
775
+		if (empty($this->checkout->reg_steps)) {
776
+			EE_Error::add_error(
777
+				__('No Reg Steps were loaded..', 'event_espresso'),
778
+				__FILE__, __FUNCTION__, __LINE__
779
+			);
780
+			return false;
781
+		}
782
+		// make reg step details available to JS
783
+		$this->checkout->set_reg_step_JSON_info();
784
+		return true;
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 *     _load_and_instantiate_reg_step
791
+	 *
792
+	 * @access    private
793
+	 * @param array $reg_step
794
+	 * @param int   $order
795
+	 * @return bool
796
+	 */
797
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
+	{
799
+		// we need a file_path, class_name, and slug to add a reg step
800
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
+			if (
803
+				$this->checkout->reg_url_link
804
+				&& $this->checkout->step !== $reg_step['slug']
805
+				&& $reg_step['slug'] !== 'finalize_registration'
806
+				// normally at this point we would NOT load the reg step, but this filter can change that
807
+				&& apply_filters(
808
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
+					true,
810
+					$reg_step,
811
+					$this->checkout
812
+				)
813
+			) {
814
+				return true;
815
+			}
816
+			// instantiate step class using file path and class name
817
+			$reg_step_obj = EE_Registry::instance()->load_file(
818
+				$reg_step['file_path'],
819
+				$reg_step['class_name'],
820
+				'class',
821
+				$this->checkout,
822
+				false
823
+			);
824
+			// did we gets the goods ?
825
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
+				// set reg step order based on config
827
+				$reg_step_obj->set_order($order);
828
+				// add instantiated reg step object to the master reg steps array
829
+				$this->checkout->add_reg_step($reg_step_obj);
830
+			} else {
831
+				EE_Error::add_error(
832
+					__('The current step could not be set.', 'event_espresso'),
833
+					__FILE__, __FUNCTION__, __LINE__
834
+				);
835
+				return false;
836
+			}
837
+		} else {
838
+			if (WP_DEBUG) {
839
+				EE_Error::add_error(
840
+					sprintf(
841
+						__(
842
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
843
+							'event_espresso'
844
+						),
845
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
+						'<ul>',
849
+						'<li>',
850
+						'</li>',
851
+						'</ul>'
852
+					),
853
+					__FILE__, __FUNCTION__, __LINE__
854
+				);
855
+			}
856
+			return false;
857
+		}
858
+		return true;
859
+	}
860
+
861
+
862
+	/**
863
+	 * _verify_transaction_and_get_registrations
864
+	 *
865
+	 * @access private
866
+	 * @return bool
867
+	 * @throws InvalidDataTypeException
868
+	 * @throws InvalidEntityException
869
+	 * @throws EE_Error
870
+	 */
871
+	private function _verify_transaction_and_get_registrations()
872
+	{
873
+		// was there already a valid transaction in the checkout from the session ?
874
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
+			// get transaction from db or session
876
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
+				? $this->_get_transaction_and_cart_for_previous_visit()
878
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
879
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
+				EE_Error::add_error(
881
+					__('Your Registration and Transaction information could not be retrieved from the db.',
882
+						'event_espresso'),
883
+					__FILE__, __FUNCTION__, __LINE__
884
+				);
885
+				$this->checkout->transaction = EE_Transaction::new_instance();
886
+				// add some style and make it dance
887
+				$this->add_styles_and_scripts();
888
+				EED_Single_Page_Checkout::$_initialized = true;
889
+				return false;
890
+			}
891
+			// and the registrations for the transaction
892
+			$this->_get_registrations($this->checkout->transaction);
893
+		}
894
+		return true;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _get_transaction_and_cart_for_previous_visit
901
+	 *
902
+	 * @access private
903
+	 * @return mixed EE_Transaction|NULL
904
+	 */
905
+	private function _get_transaction_and_cart_for_previous_visit()
906
+	{
907
+		/** @var $TXN_model EEM_Transaction */
908
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
909
+		// because the reg_url_link is present in the request,
910
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
911
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
+		// verify transaction
913
+		if ($transaction instanceof EE_Transaction) {
914
+			// and get the cart that was used for that transaction
915
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
+			return $transaction;
917
+		}
918
+		EE_Error::add_error(
919
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
+			__FILE__, __FUNCTION__, __LINE__
921
+		);
922
+		return null;
923
+
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * _get_cart_for_transaction
930
+	 *
931
+	 * @access private
932
+	 * @param EE_Transaction $transaction
933
+	 * @return EE_Cart
934
+	 */
935
+	private function _get_cart_for_transaction($transaction)
936
+	{
937
+		return $this->checkout->get_cart_for_transaction($transaction);
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * get_cart_for_transaction
944
+	 *
945
+	 * @access public
946
+	 * @param EE_Transaction $transaction
947
+	 * @return EE_Cart
948
+	 */
949
+	public function get_cart_for_transaction(EE_Transaction $transaction)
950
+	{
951
+		return $this->checkout->get_cart_for_transaction($transaction);
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * _get_transaction_and_cart_for_current_session
958
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
+	 *
960
+	 * @access private
961
+	 * @return EE_Transaction
962
+	 * @throws EE_Error
963
+	 */
964
+	private function _get_cart_for_current_session_and_setup_new_transaction()
965
+	{
966
+		//  if there's no transaction, then this is the FIRST visit to SPCO
967
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
969
+		// and then create a new transaction
970
+		$transaction = $this->_initialize_transaction();
971
+		// verify transaction
972
+		if ($transaction instanceof EE_Transaction) {
973
+			// save it so that we have an ID for other objects to use
974
+			$transaction->save();
975
+			// and save TXN data to the cart
976
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
+		} else {
978
+			EE_Error::add_error(
979
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
980
+				__FILE__, __FUNCTION__, __LINE__
981
+			);
982
+		}
983
+		return $transaction;
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
+	 *
991
+	 * @access private
992
+	 * @return mixed EE_Transaction|NULL
993
+	 */
994
+	private function _initialize_transaction()
995
+	{
996
+		try {
997
+			// ensure cart totals have been calculated
998
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
+			// grab the cart grand total
1000
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1001
+			// create new TXN
1002
+			$transaction = EE_Transaction::new_instance(
1003
+				array(
1004
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
+					'TXN_paid'      => 0,
1007
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1008
+				)
1009
+			);
1010
+			// save it so that we have an ID for other objects to use
1011
+			$transaction->save();
1012
+			// set cron job for following up on TXNs after their session has expired
1013
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1014
+				EE_Registry::instance()->SSN->expiration() + 1,
1015
+				$transaction->ID()
1016
+			);
1017
+			return $transaction;
1018
+		} catch (Exception $e) {
1019
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
+		}
1021
+		return null;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * _get_registrations
1027
+	 *
1028
+	 * @access private
1029
+	 * @param EE_Transaction $transaction
1030
+	 * @return void
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidEntityException
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	private function _get_registrations(EE_Transaction $transaction)
1036
+	{
1037
+		// first step: grab the registrants  { : o
1038
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
+		$this->checkout->total_ticket_count = count($registrations);
1040
+		// verify registrations have been set
1041
+		if (empty($registrations)) {
1042
+			// if no cached registrations, then check the db
1043
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
+			// still nothing ? well as long as this isn't a revisit
1045
+			if (empty($registrations) && ! $this->checkout->revisit) {
1046
+				// generate new registrations from scratch
1047
+				$registrations = $this->_initialize_registrations($transaction);
1048
+			}
1049
+		}
1050
+		// sort by their original registration order
1051
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
+		// then loop thru the array
1053
+		foreach ($registrations as $registration) {
1054
+			// verify each registration
1055
+			if ($registration instanceof EE_Registration) {
1056
+				// we display all attendee info for the primary registrant
1057
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
+					&& $registration->is_primary_registrant()
1059
+				) {
1060
+					$this->checkout->primary_revisit = true;
1061
+					break;
1062
+				}
1063
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
+					// but hide info if it doesn't belong to you
1065
+					$transaction->clear_cache('Registration', $registration->ID());
1066
+					$this->checkout->total_ticket_count--;
1067
+				}
1068
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1069
+			}
1070
+		}
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
+	 *
1077
+	 * @access private
1078
+	 * @param EE_Transaction $transaction
1079
+	 * @return    array
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidEntityException
1082
+	 * @throws EE_Error
1083
+	 */
1084
+	private function _initialize_registrations(EE_Transaction $transaction)
1085
+	{
1086
+		$att_nmbr = 0;
1087
+		$registrations = array();
1088
+		if ($transaction instanceof EE_Transaction) {
1089
+			/** @type EE_Registration_Processor $registration_processor */
1090
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
+			// now let's add the cart items to the $transaction
1093
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
+				//do the following for each ticket of this type they selected
1095
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
+					$att_nmbr++;
1097
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1099
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
+						array(
1101
+							$transaction,
1102
+							$line_item,
1103
+							$att_nmbr,
1104
+							$this->checkout->total_ticket_count,
1105
+						)
1106
+					);
1107
+					// override capabilities for frontend registrations
1108
+					if ( ! is_admin()) {
1109
+						$CreateRegistrationCommand->setCapCheck(
1110
+							new PublicCapabilities('', 'create_new_registration')
1111
+						);
1112
+					}
1113
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
+					if ( ! $registration instanceof EE_Registration) {
1115
+						throw new InvalidEntityException($registration, 'EE_Registration');
1116
+					}
1117
+					$registrations[ $registration->ID() ] = $registration;
1118
+				}
1119
+			}
1120
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
+		}
1122
+		return $registrations;
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * sorts registrations by REG_count
1129
+	 *
1130
+	 * @access public
1131
+	 * @param EE_Registration $reg_A
1132
+	 * @param EE_Registration $reg_B
1133
+	 * @return int
1134
+	 */
1135
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
+	{
1137
+		// this shouldn't ever happen within the same TXN, but oh well
1138
+		if ($reg_A->count() === $reg_B->count()) {
1139
+			return 0;
1140
+		}
1141
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
+	}
1143
+
1144
+
1145
+
1146
+	/**
1147
+	 *    _final_verifications
1148
+	 * just makes sure that everything is set up correctly before proceeding
1149
+	 *
1150
+	 * @access    private
1151
+	 * @return    bool
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	private function _final_verifications()
1155
+	{
1156
+		// filter checkout
1157
+		$this->checkout = apply_filters(
1158
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
+			$this->checkout
1160
+		);
1161
+		//verify that current step is still set correctly
1162
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
+			EE_Error::add_error(
1164
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1165
+				__FILE__,
1166
+				__FUNCTION__,
1167
+				__LINE__
1168
+			);
1169
+			return false;
1170
+		}
1171
+		// if returning to SPCO, then verify that primary registrant is set
1172
+		if ( ! empty($this->checkout->reg_url_link)) {
1173
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1174
+			if ( ! $valid_registrant instanceof EE_Registration) {
1175
+				EE_Error::add_error(
1176
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1177
+					__FILE__,
1178
+					__FUNCTION__,
1179
+					__LINE__
1180
+				);
1181
+				return false;
1182
+			}
1183
+			$valid_registrant = null;
1184
+			foreach (
1185
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
+			) {
1187
+				if (
1188
+					$registration instanceof EE_Registration
1189
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1190
+				) {
1191
+					$valid_registrant = $registration;
1192
+				}
1193
+			}
1194
+			if ( ! $valid_registrant instanceof EE_Registration) {
1195
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
+					// clear the session, mark the checkout as unverified, and try again
1198
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
+					EED_Single_Page_Checkout::$_initialized = false;
1200
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1201
+					$this->_initialize();
1202
+					EE_Error::reset_notices();
1203
+					return false;
1204
+				}
1205
+				EE_Error::add_error(
1206
+					__(
1207
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1208
+						'event_espresso'
1209
+					),
1210
+					__FILE__,
1211
+					__FUNCTION__,
1212
+					__LINE__
1213
+				);
1214
+				return false;
1215
+			}
1216
+		}
1217
+		// now that things have been kinda sufficiently verified,
1218
+		// let's add the checkout to the session so that it's available to other systems
1219
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
+		return true;
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 *    _initialize_reg_steps
1227
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
+	 *
1230
+	 * @access    private
1231
+	 * @param bool $reinitializing
1232
+	 * @throws EE_Error
1233
+	 */
1234
+	private function _initialize_reg_steps($reinitializing = false)
1235
+	{
1236
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
+		foreach ($this->checkout->reg_steps as $reg_step) {
1239
+			if ( ! $reg_step->initialize_reg_step()) {
1240
+				// if not initialized then maybe this step is being removed...
1241
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
+					// if it was the current step, then we need to start over here
1243
+					$this->_initialize_reg_steps(true);
1244
+					return;
1245
+				}
1246
+				continue;
1247
+			}
1248
+			// add css and JS for current step
1249
+			$reg_step->enqueue_styles_and_scripts();
1250
+			// i18n
1251
+			$reg_step->translate_js_strings();
1252
+			if ($reg_step->is_current_step()) {
1253
+				// the text that appears on the reg step form submit button
1254
+				$reg_step->set_submit_button_text();
1255
+			}
1256
+		}
1257
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
+		do_action(
1259
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
+			$this->checkout->current_step
1261
+		);
1262
+	}
1263
+
1264
+
1265
+
1266
+	/**
1267
+	 * _check_form_submission
1268
+	 *
1269
+	 * @access private
1270
+	 * @return boolean
1271
+	 */
1272
+	private function _check_form_submission()
1273
+	{
1274
+		//does this request require the reg form to be generated ?
1275
+		if ($this->checkout->generate_reg_form) {
1276
+			// ever heard that song by Blue Rodeo ?
1277
+			try {
1278
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
+				// if not displaying a form, then check for form submission
1280
+				if (
1281
+					$this->checkout->process_form_submission
1282
+					&& $this->checkout->current_step->reg_form->was_submitted()
1283
+				) {
1284
+					// clear out any old data in case this step is being run again
1285
+					$this->checkout->current_step->set_valid_data(array());
1286
+					// capture submitted form data
1287
+					$this->checkout->current_step->reg_form->receive_form_submission(
1288
+						apply_filters(
1289
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
+							EE_Registry::instance()->REQ->params(),
1291
+							$this->checkout
1292
+						)
1293
+					);
1294
+					// validate submitted form data
1295
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
+						// thou shall not pass !!!
1297
+						$this->checkout->continue_reg = false;
1298
+						// any form validation errors?
1299
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
+							$submission_error_messages = array();
1301
+							// bad, bad, bad registrant
1302
+							foreach (
1303
+								$this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1304
+								as $validation_error
1305
+							) {
1306
+								if ($validation_error instanceof EE_Validation_Error) {
1307
+									$submission_error_messages[] = sprintf(
1308
+										__('%s : %s', 'event_espresso'),
1309
+										$validation_error->get_form_section()->html_label_text(),
1310
+										$validation_error->getMessage()
1311
+									);
1312
+								}
1313
+							}
1314
+							EE_Error::add_error(
1315
+								implode('<br />', $submission_error_messages),
1316
+								__FILE__, __FUNCTION__, __LINE__
1317
+							);
1318
+						}
1319
+						// well not really... what will happen is
1320
+						// we'll just get redirected back to redo the current step
1321
+						$this->go_to_next_step();
1322
+						return false;
1323
+					}
1324
+				}
1325
+			} catch (EE_Error $e) {
1326
+				$e->get_error();
1327
+			}
1328
+		}
1329
+		return true;
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * _process_action
1336
+	 *
1337
+	 * @access private
1338
+	 * @return void
1339
+	 * @throws EE_Error
1340
+	 */
1341
+	private function _process_form_action()
1342
+	{
1343
+		// what cha wanna do?
1344
+		switch ($this->checkout->action) {
1345
+			// AJAX next step reg form
1346
+			case 'display_spco_reg_step' :
1347
+				$this->checkout->redirect = false;
1348
+				if (EE_Registry::instance()->REQ->ajax) {
1349
+					$this->checkout->json_response->set_reg_step_html(
1350
+						$this->checkout->current_step->display_reg_form()
1351
+					);
1352
+				}
1353
+				break;
1354
+			default :
1355
+				// meh... do one of those other steps first
1356
+				if (
1357
+					! empty($this->checkout->action)
1358
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1359
+				) {
1360
+					// dynamically creates hook point like:
1361
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1362
+					do_action(
1363
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1364
+						$this->checkout->current_step
1365
+					);
1366
+					// call action on current step
1367
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1368
+						// good registrant, you get to proceed
1369
+						if (
1370
+							$this->checkout->current_step->success_message() !== ''
1371
+							&& apply_filters(
1372
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1373
+								false
1374
+							)
1375
+						) {
1376
+							EE_Error::add_success(
1377
+								$this->checkout->current_step->success_message()
1378
+								. '<br />' . $this->checkout->next_step->_instructions()
1379
+							);
1380
+						}
1381
+						// pack it up, pack it in...
1382
+						$this->_setup_redirect();
1383
+					}
1384
+					// dynamically creates hook point like:
1385
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1386
+					do_action(
1387
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1388
+						$this->checkout->current_step
1389
+					);
1390
+				} else {
1391
+					EE_Error::add_error(
1392
+						sprintf(
1393
+							__(
1394
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1395
+								'event_espresso'
1396
+							),
1397
+							$this->checkout->action,
1398
+							$this->checkout->current_step->name()
1399
+						),
1400
+						__FILE__,
1401
+						__FUNCTION__,
1402
+						__LINE__
1403
+					);
1404
+				}
1405
+			// end default
1406
+		}
1407
+		// store our progress so far
1408
+		$this->checkout->stash_transaction_and_checkout();
1409
+		// advance to the next step! If you pass GO, collect $200
1410
+		$this->go_to_next_step();
1411
+	}
1412
+
1413
+
1414
+
1415
+	/**
1416
+	 *        add_styles_and_scripts
1417
+	 *
1418
+	 * @access        public
1419
+	 * @return        void
1420
+	 */
1421
+	public function add_styles_and_scripts()
1422
+	{
1423
+		// i18n
1424
+		$this->translate_js_strings();
1425
+		if ($this->checkout->admin_request) {
1426
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1427
+		} else {
1428
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1429
+		}
1430
+	}
1431
+
1432
+
1433
+
1434
+	/**
1435
+	 *        translate_js_strings
1436
+	 *
1437
+	 * @access        public
1438
+	 * @return        void
1439
+	 */
1440
+	public function translate_js_strings()
1441
+	{
1442
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1443
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1444
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1445
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1446
+			'event_espresso'
1447
+		);
1448
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1449
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1450
+			'event_espresso'
1451
+		);
1452
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1453
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1454
+			'event_espresso'
1455
+		);
1456
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1457
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1458
+			'event_espresso'
1459
+		);
1460
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1461
+			'This registration step could not be completed. Please refresh the page and try again.',
1462
+			'event_espresso'
1463
+		);
1464
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1465
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1466
+			'event_espresso'
1467
+		);
1468
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1469
+			__(
1470
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1471
+				'event_espresso'
1472
+			),
1473
+			'<br/>',
1474
+			'<br/>'
1475
+		);
1476
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1477
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1478
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1479
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1480
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1481
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1482
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1483
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1484
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1485
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1486
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1487
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1488
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1489
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1490
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1491
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1492
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1493
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1494
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1495
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1496
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1497
+			true
1498
+		);
1499
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1500
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1501
+		);
1502
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1503
+			'M d, Y H:i:s',
1504
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1505
+		);
1506
+	}
1507
+
1508
+
1509
+
1510
+	/**
1511
+	 *    enqueue_styles_and_scripts
1512
+	 *
1513
+	 * @access        public
1514
+	 * @return        void
1515
+	 * @throws EE_Error
1516
+	 */
1517
+	public function enqueue_styles_and_scripts()
1518
+	{
1519
+		// load css
1520
+		wp_register_style(
1521
+			'single_page_checkout',
1522
+			SPCO_CSS_URL . 'single_page_checkout.css',
1523
+			array('espresso_default'),
1524
+			EVENT_ESPRESSO_VERSION
1525
+		);
1526
+		wp_enqueue_style('single_page_checkout');
1527
+		// load JS
1528
+		wp_register_script(
1529
+			'jquery_plugin',
1530
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1531
+			array('jquery'),
1532
+			'1.0.1',
1533
+			true
1534
+		);
1535
+		wp_register_script(
1536
+			'jquery_countdown',
1537
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1538
+			array('jquery_plugin'),
1539
+			'2.0.2',
1540
+			true
1541
+		);
1542
+		wp_register_script(
1543
+			'single_page_checkout',
1544
+			SPCO_JS_URL . 'single_page_checkout.js',
1545
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1546
+			EVENT_ESPRESSO_VERSION,
1547
+			true
1548
+		);
1549
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1550
+			$this->checkout->registration_form->enqueue_js();
1551
+		}
1552
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1553
+			$this->checkout->current_step->reg_form->enqueue_js();
1554
+		}
1555
+		wp_enqueue_script('single_page_checkout');
1556
+		/**
1557
+		 * global action hook for enqueueing styles and scripts with
1558
+		 * spco calls.
1559
+		 */
1560
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1561
+		/**
1562
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1563
+		 * The hook will end up being something like:
1564
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1565
+		 */
1566
+		do_action(
1567
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1568
+			$this
1569
+		);
1570
+	}
1571
+
1572
+
1573
+
1574
+	/**
1575
+	 *    display the Registration Single Page Checkout Form
1576
+	 *
1577
+	 * @access    private
1578
+	 * @return    void
1579
+	 * @throws EE_Error
1580
+	 */
1581
+	private function _display_spco_reg_form()
1582
+	{
1583
+		// if registering via the admin, just display the reg form for the current step
1584
+		if ($this->checkout->admin_request) {
1585
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1586
+		} else {
1587
+			// add powered by EE msg
1588
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1589
+			$empty_cart = count(
1590
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1591
+			) < 1;
1592
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1593
+			$cookies_not_set_msg = '';
1594
+			if ($empty_cart) {
1595
+				$cookies_not_set_msg = apply_filters(
1596
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1597
+					sprintf(
1598
+						__(
1599
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1600
+							'event_espresso'
1601
+						),
1602
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1603
+						'</div>',
1604
+						'<h6 class="important-notice">',
1605
+						'</h6>',
1606
+						'<p>',
1607
+						'</p>',
1608
+						'<br />',
1609
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1610
+						'</a>'
1611
+					)
1612
+				);
1613
+			}
1614
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1615
+				array(
1616
+					'name'            => 'single-page-checkout',
1617
+					'html_id'         => 'ee-single-page-checkout-dv',
1618
+					'layout_strategy' =>
1619
+						new EE_Template_Layout(
1620
+							array(
1621
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1622
+								'template_args'        => array(
1623
+									'empty_cart'              => $empty_cart,
1624
+									'revisit'                 => $this->checkout->revisit,
1625
+									'reg_steps'               => $this->checkout->reg_steps,
1626
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1627
+										? $this->checkout->next_step->slug()
1628
+										: '',
1629
+									'empty_msg'               => apply_filters(
1630
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1631
+										sprintf(
1632
+											__(
1633
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1634
+												'event_espresso'
1635
+											),
1636
+											'<a href="'
1637
+											. get_post_type_archive_link('espresso_events')
1638
+											. '" title="',
1639
+											'">',
1640
+											'</a>'
1641
+										)
1642
+									),
1643
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1644
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1645
+									'session_expiration'      => gmdate(
1646
+										'M d, Y H:i:s',
1647
+										EE_Registry::instance()->SSN->expiration()
1648
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1649
+									),
1650
+								),
1651
+							)
1652
+						),
1653
+				)
1654
+			);
1655
+			// load template and add to output sent that gets filtered into the_content()
1656
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1657
+		}
1658
+	}
1659
+
1660
+
1661
+
1662
+	/**
1663
+	 *    add_extra_finalize_registration_inputs
1664
+	 *
1665
+	 * @access    public
1666
+	 * @param $next_step
1667
+	 * @internal  param string $label
1668
+	 * @return void
1669
+	 */
1670
+	public function add_extra_finalize_registration_inputs($next_step)
1671
+	{
1672
+		if ($next_step === 'finalize_registration') {
1673
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1674
+		}
1675
+	}
1676
+
1677
+
1678
+
1679
+	/**
1680
+	 *    display_registration_footer
1681
+	 *
1682
+	 * @access    public
1683
+	 * @return    string
1684
+	 */
1685
+	public static function display_registration_footer()
1686
+	{
1687
+		if (
1688
+		apply_filters(
1689
+			'FHEE__EE_Front__Controller__show_reg_footer',
1690
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1691
+		)
1692
+		) {
1693
+			add_filter(
1694
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1695
+				function ($url) {
1696
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1697
+				}
1698
+			);
1699
+			echo apply_filters(
1700
+				'FHEE__EE_Front_Controller__display_registration_footer',
1701
+				\EEH_Template::powered_by_event_espresso(
1702
+					'',
1703
+					'espresso-registration-footer-dv',
1704
+					array('utm_content' => 'registration_checkout')
1705
+				)
1706
+			);
1707
+		}
1708
+		return '';
1709
+	}
1710
+
1711
+
1712
+
1713
+	/**
1714
+	 *    unlock_transaction
1715
+	 *
1716
+	 * @access    public
1717
+	 * @return    void
1718
+	 * @throws EE_Error
1719
+	 */
1720
+	public function unlock_transaction()
1721
+	{
1722
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1723
+			$this->checkout->transaction->unlock();
1724
+		}
1725
+	}
1726
+
1727
+
1728
+
1729
+	/**
1730
+	 *        _setup_redirect
1731
+	 *
1732
+	 * @access    private
1733
+	 * @return void
1734
+	 */
1735
+	private function _setup_redirect()
1736
+	{
1737
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1738
+			$this->checkout->redirect = true;
1739
+			if (empty($this->checkout->redirect_url)) {
1740
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1741
+			}
1742
+			$this->checkout->redirect_url = apply_filters(
1743
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1744
+				$this->checkout->redirect_url,
1745
+				$this->checkout
1746
+			);
1747
+		}
1748
+	}
1749
+
1750
+
1751
+
1752
+	/**
1753
+	 *   handle ajax message responses and redirects
1754
+	 *
1755
+	 * @access public
1756
+	 * @return void
1757
+	 * @throws EE_Error
1758
+	 */
1759
+	public function go_to_next_step()
1760
+	{
1761
+		if (EE_Registry::instance()->REQ->ajax) {
1762
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1763
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1764
+		}
1765
+		$this->unlock_transaction();
1766
+		// just return for these conditions
1767
+		if (
1768
+			$this->checkout->admin_request
1769
+			|| $this->checkout->action === 'redirect_form'
1770
+			|| $this->checkout->action === 'update_checkout'
1771
+		) {
1772
+			return;
1773
+		}
1774
+		// AJAX response
1775
+		$this->_handle_json_response();
1776
+		// redirect to next step or the Thank You page
1777
+		$this->_handle_html_redirects();
1778
+		// hmmm... must be something wrong, so let's just display the form again !
1779
+		$this->_display_spco_reg_form();
1780
+	}
1781
+
1782
+
1783
+
1784
+	/**
1785
+	 *   _handle_json_response
1786
+	 *
1787
+	 * @access protected
1788
+	 * @return void
1789
+	 */
1790
+	protected function _handle_json_response()
1791
+	{
1792
+		// if this is an ajax request
1793
+		if (EE_Registry::instance()->REQ->ajax) {
1794
+			// DEBUG LOG
1795
+			//$this->checkout->log(
1796
+			//	__CLASS__, __FUNCTION__, __LINE__,
1797
+			//	array(
1798
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1799
+			//		'redirect'                   => $this->checkout->redirect,
1800
+			//		'continue_reg'               => $this->checkout->continue_reg,
1801
+			//	)
1802
+			//);
1803
+			$this->checkout->json_response->set_registration_time_limit(
1804
+				$this->checkout->get_registration_time_limit()
1805
+			);
1806
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1807
+			// just send the ajax (
1808
+			$json_response = apply_filters(
1809
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1810
+				$this->checkout->json_response
1811
+			);
1812
+			echo $json_response;
1813
+			exit();
1814
+		}
1815
+	}
1816
+
1817
+
1818
+
1819
+	/**
1820
+	 *   _handle_redirects
1821
+	 *
1822
+	 * @access protected
1823
+	 * @return void
1824
+	 */
1825
+	protected function _handle_html_redirects()
1826
+	{
1827
+		// going somewhere ?
1828
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1829
+			// store notices in a transient
1830
+			EE_Error::get_notices(false, true, true);
1831
+			// DEBUG LOG
1832
+			//$this->checkout->log(
1833
+			//	__CLASS__, __FUNCTION__, __LINE__,
1834
+			//	array(
1835
+			//		'headers_sent' => headers_sent(),
1836
+			//		'redirect_url'     => $this->checkout->redirect_url,
1837
+			//		'headers_list'    => headers_list(),
1838
+			//	)
1839
+			//);
1840
+			wp_safe_redirect($this->checkout->redirect_url);
1841
+			exit();
1842
+		}
1843
+	}
1844
+
1845
+
1846
+
1847
+	/**
1848
+	 *   set_checkout_anchor
1849
+	 *
1850
+	 * @access public
1851
+	 * @return void
1852
+	 */
1853
+	public function set_checkout_anchor()
1854
+	{
1855
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1856
+	}
1857
+
1858
+	/**
1859
+	 *    getRegistrationExpirationNotice
1860
+	 *
1861
+	 * @since $VID:$
1862
+	 * @access    public
1863
+	 * @return    string
1864
+	 */
1865
+	public static function getRegistrationExpirationNotice()
1866
+	{
1867
+		return sprintf(
1868
+			__('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1869
+				'event_espresso'),
1870
+			'<h4 class="important-notice">',
1871
+			'</h4>',
1872
+			'<br />',
1873
+			'<p>',
1874
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1875
+			'">',
1876
+			'</a>',
1877
+			'</p>'
1878
+		);
1879
+	}
1880 1880
 
1881 1881
 }
1882 1882
 // End of file EED_Single_Page_Checkout.module.php
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function set_definitions()
220 220
     {
221
-        if(defined('SPCO_BASE_PATH')) {
221
+        if (defined('SPCO_BASE_PATH')) {
222 222
             return;
223 223
         }
224 224
         define(
225 225
             'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
226
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
227 227
         );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
228
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
229
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
230
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
231
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
232
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
233
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
234 234
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235 235
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236 236
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
             return;
252 252
         }
253 253
         // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
254
+        $reg_steps_to_load = (array) apply_filters(
255 255
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256 256
             EED_Single_Page_Checkout::get_reg_steps()
257 257
         );
@@ -303,25 +303,25 @@  discard block
 block discarded – undo
303 303
         if (empty($reg_steps)) {
304 304
             $reg_steps = array(
305 305
                 10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
306
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
307 307
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308 308
                     'slug'       => 'attendee_information',
309 309
                     'has_hooks'  => false,
310 310
                 ),
311 311
                 20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
312
+                    'file_path'  => SPCO_REG_STEPS_PATH.'registration_confirmation',
313 313
                     'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314 314
                     'slug'       => 'registration_confirmation',
315 315
                     'has_hooks'  => false,
316 316
                 ),
317 317
                 30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
318
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
319 319
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320 320
                     'slug'       => 'payment_options',
321 321
                     'has_hooks'  => true,
322 322
                 ),
323 323
                 999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
324
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
325 325
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326 326
                     'slug'       => 'finalize_registration',
327 327
                     'has_hooks'  => false,
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             // DEBUG LOG
506 506
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507 507
             // get reg form
508
-            if( ! $this->_check_form_submission()) {
508
+            if ( ! $this->_check_form_submission()) {
509 509
                 EED_Single_Page_Checkout::$_initialized = true;
510 510
                 return;
511 511
             }
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
         );
547 547
         // is session still valid ?
548 548
         if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
549
+            || (EE_Registry::instance()->SSN->expired()
550 550
               && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551 551
             )
552 552
         ) {
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             // EE_Registry::instance()->SSN->reset_cart();
556 556
             // EE_Registry::instance()->SSN->reset_checkout();
557 557
             // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
558
+            if ( ! $clear_session_requested) {
559 559
                 EE_Error::add_attention(
560 560
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561 561
                     __FILE__, __FUNCTION__, __LINE__
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
                     if ( ! $registration instanceof EE_Registration) {
1115 1115
                         throw new InvalidEntityException($registration, 'EE_Registration');
1116 1116
                     }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1117
+                    $registrations[$registration->ID()] = $registration;
1118 1118
                 }
1119 1119
             }
1120 1120
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
                         ) {
1376 1376
                             EE_Error::add_success(
1377 1377
                                 $this->checkout->current_step->success_message()
1378
-                                . '<br />' . $this->checkout->next_step->_instructions()
1378
+                                . '<br />'.$this->checkout->next_step->_instructions()
1379 1379
                             );
1380 1380
                         }
1381 1381
                         // pack it up, pack it in...
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
         // load css
1520 1520
         wp_register_style(
1521 1521
             'single_page_checkout',
1522
-            SPCO_CSS_URL . 'single_page_checkout.css',
1522
+            SPCO_CSS_URL.'single_page_checkout.css',
1523 1523
             array('espresso_default'),
1524 1524
             EVENT_ESPRESSO_VERSION
1525 1525
         );
@@ -1527,21 +1527,21 @@  discard block
 block discarded – undo
1527 1527
         // load JS
1528 1528
         wp_register_script(
1529 1529
             'jquery_plugin',
1530
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1530
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1531 1531
             array('jquery'),
1532 1532
             '1.0.1',
1533 1533
             true
1534 1534
         );
1535 1535
         wp_register_script(
1536 1536
             'jquery_countdown',
1537
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1537
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1538 1538
             array('jquery_plugin'),
1539 1539
             '2.0.2',
1540 1540
             true
1541 1541
         );
1542 1542
         wp_register_script(
1543 1543
             'single_page_checkout',
1544
-            SPCO_JS_URL . 'single_page_checkout.js',
1544
+            SPCO_JS_URL.'single_page_checkout.js',
1545 1545
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1546 1546
             EVENT_ESPRESSO_VERSION,
1547 1547
             true
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1565 1565
          */
1566 1566
         do_action(
1567
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1567
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1568 1568
             $this
1569 1569
         );
1570 1570
     }
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
                     'layout_strategy' =>
1619 1619
                         new EE_Template_Layout(
1620 1620
                             array(
1621
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1621
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1622 1622
                                 'template_args'        => array(
1623 1623
                                     'empty_cart'              => $empty_cart,
1624 1624
                                     'revisit'                 => $this->checkout->revisit,
@@ -1692,7 +1692,7 @@  discard block
 block discarded – undo
1692 1692
         ) {
1693 1693
             add_filter(
1694 1694
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1695
-                function ($url) {
1695
+                function($url) {
1696 1696
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1697 1697
                 }
1698 1698
             );
@@ -1871,7 +1871,7 @@  discard block
 block discarded – undo
1871 1871
             '</h4>',
1872 1872
             '<br />',
1873 1873
             '<p>',
1874
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1874
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1875 1875
             '">',
1876 1876
             '</a>',
1877 1877
             '</p>'
Please login to merge, or discard this patch.