Completed
Branch decaf-fixes/main (429204)
by
unknown
02:34 queued 10s
created
public/Espresso_Arabica_2014/content-espresso_events-venues.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,75 +1,75 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (
4
-	( is_single() && espresso_display_venue_in_event_details() )
5
-	|| ( is_archive() && espresso_display_venue_in_event_list() )
4
+	(is_single() && espresso_display_venue_in_event_details())
5
+	|| (is_archive() && espresso_display_venue_in_event_list())
6 6
 ) :
7 7
 	global $post;
8
-	do_action( 'AHEE_event_details_before_venue_details', $post );
9
-	$venue_name = espresso_venue_name( 0, 'details', FALSE );
10
-	if ( empty( $venue_name ) && espresso_is_venue_private() ) {
11
-		do_action( 'AHEE_event_details_after_venue_details', $post );
8
+	do_action('AHEE_event_details_before_venue_details', $post);
9
+	$venue_name = espresso_venue_name(0, 'details', FALSE);
10
+	if (empty($venue_name) && espresso_is_venue_private()) {
11
+		do_action('AHEE_event_details_after_venue_details', $post);
12 12
 		return '';
13 13
 	}
14 14
 ?>
15 15
 
16 16
 <div class="espresso-venue-dv<?php echo espresso_is_venue_private() ? ' espresso-private-venue-dv' : ''; ?>">
17 17
 	<h4>
18
-        <strong><?php esc_html_e( 'Venue:', 'event_espresso' ); ?></strong>&nbsp;&nbsp;
18
+        <strong><?php esc_html_e('Venue:', 'event_espresso'); ?></strong>&nbsp;&nbsp;
19 19
         <strong> <?php echo $venue_name; // already escaped ?></strong>
20 20
     </h4>
21 21
 	<p><span class="smaller-text tags-links"><?php echo espresso_venue_categories(); ?></span></p>
22
-<?php  if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?>
22
+<?php  if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?>
23 23
 	<p>
24 24
 		<span class="small-text">
25
-            <strong><?php esc_html_e( 'Venue Phone:', 'event_espresso' ); ?></strong>
25
+            <strong><?php esc_html_e('Venue Phone:', 'event_espresso'); ?></strong>
26 26
         </span>
27 27
         <?php echo $venue_phone; // already escaped ?>
28 28
 	</p>
29
-<?php endif;  ?>
30
-<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?>
29
+<?php endif; ?>
30
+<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?>
31 31
 	<p>
32 32
 		<span class="small-text">
33
-            <strong><?php esc_html_e( 'Venue Website:', 'event_espresso' ); ?></strong>
33
+            <strong><?php esc_html_e('Venue Website:', 'event_espresso'); ?></strong>
34 34
         </span>
35 35
         <?php echo $venue_website; // already escaped ?>
36 36
 	</p>
37 37
 <?php endif; ?>
38
-<?php  if ( espresso_venue_has_address( $post->ID )) : ?>
39
-	<strong><span class="dashicons dashicons-location-alt"></span><?php esc_html_e( 'Address:', 'event_espresso' ); ?></strong>
40
-	<?php espresso_venue_address( 'inline' ); // already escaped ?>
41
-	<?php espresso_venue_gmap( $post->ID ); // already escaped ?>
38
+<?php  if (espresso_venue_has_address($post->ID)) : ?>
39
+	<strong><span class="dashicons dashicons-location-alt"></span><?php esc_html_e('Address:', 'event_espresso'); ?></strong>
40
+	<?php espresso_venue_address('inline'); // already escaped ?>
41
+	<?php espresso_venue_gmap($post->ID); // already escaped ?>
42 42
 	<div class="clear"><br/></div>
43
-<?php endif;  ?>
43
+<?php endif; ?>
44 44
 
45
-	<?php $VNU_ID = espresso_venue_id( $post->ID ); ?>
46
-	<?php if ( is_single() ) : ?>
47
-		<?php $venue_description = espresso_venue_description( $VNU_ID, FALSE ); ?>
48
-		<?php if ( $venue_description ) : ?>
45
+	<?php $VNU_ID = espresso_venue_id($post->ID); ?>
46
+	<?php if (is_single()) : ?>
47
+		<?php $venue_description = espresso_venue_description($VNU_ID, FALSE); ?>
48
+		<?php if ($venue_description) : ?>
49 49
 	<p>
50
-		<strong><?php esc_html_e( 'Description:', 'event_espresso' ); ?></strong><br/>
51
-		<?php echo do_shortcode( $venue_description ); ?>
50
+		<strong><?php esc_html_e('Description:', 'event_espresso'); ?></strong><br/>
51
+		<?php echo do_shortcode($venue_description); ?>
52 52
 	</p>
53
-		<?php endif;  ?>
53
+		<?php endif; ?>
54 54
 	<?php else : ?>
55
-		<?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?>
56
-		<?php if ( $venue_excerpt ) : ?>
55
+		<?php $venue_excerpt = espresso_venue_excerpt($VNU_ID, FALSE); ?>
56
+		<?php if ($venue_excerpt) : ?>
57 57
 	<p>
58
-		<strong><?php esc_html_e( 'Description:', 'event_espresso' ); ?></strong><br/>
58
+		<strong><?php esc_html_e('Description:', 'event_espresso'); ?></strong><br/>
59 59
 		<?php echo $venue_excerpt; ?>
60 60
 	</p>
61
-			<?php endif;  ?>
62
-		<?php endif;  ?>
61
+			<?php endif; ?>
62
+		<?php endif; ?>
63 63
 </div>
64 64
 <!-- .espresso-venue-dv -->
65 65
 <?php
66
-do_action( 'AHEE_event_details_after_venue_details', $post );
66
+do_action('AHEE_event_details_after_venue_details', $post);
67 67
 else :
68
-	if ( espresso_venue_is_password_protected() ) :
68
+	if (espresso_venue_is_password_protected()) :
69 69
 ?>
70 70
 	<div class="espresso-venue-dv  espresso-password-protected-venue-dv" >
71 71
 		<h3 class="event-venues-h3 ee-event-h3">
72
-			<?php esc_html_e( 'Location', 'event_espresso' );?>
72
+			<?php esc_html_e('Location', 'event_espresso'); ?>
73 73
 		</h3>
74 74
 		<?php echo espresso_password_protected_venue_form(); ?>
75 75
 	</div>
Please login to merge, or discard this patch.
admin_pages/events/templates/event_tickets_metabox_ticket_row.template.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -86,12 +86,15 @@  discard block
 block discarded – undo
86 86
                    name="edit_prices[<?php echo $ticketrow; ?>][1][PRC_amount]"
87 87
                    value="<?php echo esc_attr($PRC_amount); ?>"
88 88
             />
89
-        <?php else : ?>
89
+        <?php else {
90
+	: ?>
90 91
             <input type="text"
91 92
                    size="1"
92 93
                    class="edit-price-PRC_amount ee-small-text-inp ee-inp-right"
93 94
                    name="disabled_price_amount"
94
-                   value="<?php echo esc_attr($PRC_amount); ?>"
95
+                   value="<?php echo esc_attr($PRC_amount);
96
+}
97
+?>"
95 98
                 <?php echo esc_attr($disabled); ?>
96 99
             />
97 100
             <input type="hidden"
@@ -125,11 +128,14 @@  discard block
 block discarded – undo
125 128
                    name="<?php echo "{$edit_ticketrow_name}[{$ticketrow}][TKT_qty]"; ?>"
126 129
                    value="<?php echo esc_attr($TKT_qty); ?>"
127 130
             />
128
-        <?php else : ?>
131
+        <?php else {
132
+	: ?>
129 133
             <input type="text"
130 134
                    class="edit-ticket-TKT_qty ee-small-text-inp ee-inp-right"
131 135
                    name="disabled_tkt_qty"
132
-                   value="<?php echo esc_attr($TKT_qty); ?>"
136
+                   value="<?php echo esc_attr($TKT_qty);
137
+}
138
+?>"
133 139
                 <?php echo esc_attr($disabled); ?>
134 140
             />
135 141
             <input type="hidden"
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2648 added lines, -2648 removed lines patch added patch discarded remove patch
@@ -19,2652 +19,2652 @@
 block discarded – undo
19 19
 class Events_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * This will hold the event object for event_details screen.
24
-     *
25
-     * @var EE_Event $_event
26
-     */
27
-    protected $_event;
28
-
29
-
30
-    /**
31
-     * This will hold the category object for category_details screen.
32
-     *
33
-     * @var stdClass $_category
34
-     */
35
-    protected $_category;
36
-
37
-
38
-    /**
39
-     * This will hold the event model instance
40
-     *
41
-     * @var EEM_Event $_event_model
42
-     */
43
-    protected $_event_model;
44
-
45
-
46
-    /**
47
-     * @var EE_Event
48
-     */
49
-    protected $_cpt_model_obj = false;
50
-
51
-
52
-    /**
53
-     * @var NodeGroupDao
54
-     */
55
-    protected $model_obj_node_group_persister;
56
-
57
-    /**
58
-     * Initialize page props for this admin page group.
59
-     */
60
-    protected function _init_page_props()
61
-    {
62
-        $this->page_slug = EVENTS_PG_SLUG;
63
-        $this->page_label = EVENTS_LABEL;
64
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
65
-        $this->_admin_base_path = EVENTS_ADMIN;
66
-        $this->_cpt_model_names = array(
67
-            'create_new' => 'EEM_Event',
68
-            'edit'       => 'EEM_Event',
69
-        );
70
-        $this->_cpt_edit_routes = array(
71
-            'espresso_events' => 'edit',
72
-        );
73
-        add_action(
74
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
-            array($this, 'verify_event_edit'),
76
-            10,
77
-            2
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the ajax hooks used for this admin page group.
84
-     */
85
-    protected function _ajax_hooks()
86
-    {
87
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
88
-    }
89
-
90
-
91
-    /**
92
-     * Sets the page properties for this admin page group.
93
-     */
94
-    protected function _define_page_props()
95
-    {
96
-        $this->_admin_page_title = EVENTS_LABEL;
97
-        $this->_labels = array(
98
-            'buttons'      => array(
99
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
100
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
-            ),
106
-            'editor_title' => array(
107
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
-            ),
109
-            'publishbox'   => array(
110
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
112
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    /**
121
-     * Sets the page routes property for this admin page group.
122
-     */
123
-    protected function _set_page_routes()
124
-    {
125
-        // load formatter helper
126
-        // load field generator helper
127
-        // is there a evt_id in the request?
128
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
-            ? $this->_req_data['EVT_ID']
130
-            : 0;
131
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
-        $this->_page_routes = array(
133
-            'default'                       => array(
134
-                'func'       => '_events_overview_list_table',
135
-                'capability' => 'ee_read_events',
136
-            ),
137
-            'create_new'                    => array(
138
-                'func'       => '_create_new_cpt_item',
139
-                'capability' => 'ee_edit_events',
140
-            ),
141
-            'edit'                          => array(
142
-                'func'       => '_edit_cpt_item',
143
-                'capability' => 'ee_edit_event',
144
-                'obj_id'     => $evt_id,
145
-            ),
146
-            'copy_event'                    => array(
147
-                'func'       => '_copy_events',
148
-                'capability' => 'ee_edit_event',
149
-                'obj_id'     => $evt_id,
150
-                'noheader'   => true,
151
-            ),
152
-            'trash_event'                   => array(
153
-                'func'       => '_trash_or_restore_event',
154
-                'args'       => array('event_status' => 'trash'),
155
-                'capability' => 'ee_delete_event',
156
-                'obj_id'     => $evt_id,
157
-                'noheader'   => true,
158
-            ),
159
-            'trash_events'                  => array(
160
-                'func'       => '_trash_or_restore_events',
161
-                'args'       => array('event_status' => 'trash'),
162
-                'capability' => 'ee_delete_events',
163
-                'noheader'   => true,
164
-            ),
165
-            'restore_event'                 => array(
166
-                'func'       => '_trash_or_restore_event',
167
-                'args'       => array('event_status' => 'draft'),
168
-                'capability' => 'ee_delete_event',
169
-                'obj_id'     => $evt_id,
170
-                'noheader'   => true,
171
-            ),
172
-            'restore_events'                => array(
173
-                'func'       => '_trash_or_restore_events',
174
-                'args'       => array('event_status' => 'draft'),
175
-                'capability' => 'ee_delete_events',
176
-                'noheader'   => true,
177
-            ),
178
-            'delete_event'                  => array(
179
-                'func'       => '_delete_event',
180
-                'capability' => 'ee_delete_event',
181
-                'obj_id'     => $evt_id,
182
-                'noheader'   => true,
183
-            ),
184
-            'delete_events'                 => array(
185
-                'func'       => '_delete_events',
186
-                'capability' => 'ee_delete_events',
187
-                'noheader'   => true,
188
-            ),
189
-            'view_report'                   => array(
190
-                'func'      => '_view_report',
191
-                'capablity' => 'ee_edit_events',
192
-            ),
193
-            'default_event_settings'        => array(
194
-                'func'       => '_default_event_settings',
195
-                'capability' => 'manage_options',
196
-            ),
197
-            'update_default_event_settings' => array(
198
-                'func'       => '_update_default_event_settings',
199
-                'capability' => 'manage_options',
200
-                'noheader'   => true,
201
-            ),
202
-            'template_settings'             => array(
203
-                'func'       => '_template_settings',
204
-                'capability' => 'manage_options',
205
-            ),
206
-            // event category tab related
207
-            'add_category'                  => array(
208
-                'func'       => '_category_details',
209
-                'capability' => 'ee_edit_event_category',
210
-                'args'       => array('add'),
211
-            ),
212
-            'edit_category'                 => array(
213
-                'func'       => '_category_details',
214
-                'capability' => 'ee_edit_event_category',
215
-                'args'       => array('edit'),
216
-            ),
217
-            'delete_categories'             => array(
218
-                'func'       => '_delete_categories',
219
-                'capability' => 'ee_delete_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'delete_category'               => array(
223
-                'func'       => '_delete_categories',
224
-                'capability' => 'ee_delete_event_category',
225
-                'noheader'   => true,
226
-            ),
227
-            'insert_category'               => array(
228
-                'func'       => '_insert_or_update_category',
229
-                'args'       => array('new_category' => true),
230
-                'capability' => 'ee_edit_event_category',
231
-                'noheader'   => true,
232
-            ),
233
-            'update_category'               => array(
234
-                'func'       => '_insert_or_update_category',
235
-                'args'       => array('new_category' => false),
236
-                'capability' => 'ee_edit_event_category',
237
-                'noheader'   => true,
238
-            ),
239
-            'category_list'                 => array(
240
-                'func'       => '_category_list_table',
241
-                'capability' => 'ee_manage_event_categories',
242
-            ),
243
-            'preview_deletion' => [
244
-                'func' => 'previewDeletion',
245
-                'capability' => 'ee_delete_events',
246
-            ],
247
-            'confirm_deletion' => [
248
-                'func' => 'confirmDeletion',
249
-                'capability' => 'ee_delete_events',
250
-                'noheader' => true,
251
-            ]
252
-        );
253
-    }
254
-
255
-
256
-    /**
257
-     * Set the _page_config property for this admin page group.
258
-     */
259
-    protected function _set_page_config()
260
-    {
261
-        $this->_page_config = array(
262
-            'default'                => array(
263
-                'nav'           => array(
264
-                    'label' => esc_html__('Overview', 'event_espresso'),
265
-                    'order' => 10,
266
-                ),
267
-                'list_table'    => 'Events_Admin_List_Table',
268
-                'help_tabs'     => array(
269
-                    'events_overview_help_tab'                       => array(
270
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
271
-                        'filename' => 'events_overview',
272
-                    ),
273
-                    'events_overview_table_column_headings_help_tab' => array(
274
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
-                        'filename' => 'events_overview_table_column_headings',
276
-                    ),
277
-                    'events_overview_filters_help_tab'               => array(
278
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
-                        'filename' => 'events_overview_filters',
280
-                    ),
281
-                    'events_overview_view_help_tab'                  => array(
282
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
-                        'filename' => 'events_overview_views',
284
-                    ),
285
-                    'events_overview_other_help_tab'                 => array(
286
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
-                        'filename' => 'events_overview_other',
288
-                    ),
289
-                ),
290
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
-                // 'help_tour'     => array(
292
-                //     'Event_Overview_Help_Tour',
293
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
-                // ),
295
-                'qtips'         => array(
296
-                    'EE_Event_List_Table_Tips',
297
-                ),
298
-                'require_nonce' => false,
299
-            ),
300
-            'create_new'             => array(
301
-                'nav'           => array(
302
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
303
-                    'order'      => 5,
304
-                    'persistent' => false,
305
-                ),
306
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
307
-                'help_tabs'     => array(
308
-                    'event_editor_help_tab'                            => array(
309
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
310
-                        'filename' => 'event_editor',
311
-                    ),
312
-                    'event_editor_title_richtexteditor_help_tab'       => array(
313
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
314
-                        'filename' => 'event_editor_title_richtexteditor',
315
-                    ),
316
-                    'event_editor_venue_details_help_tab'              => array(
317
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
318
-                        'filename' => 'event_editor_venue_details',
319
-                    ),
320
-                    'event_editor_event_datetimes_help_tab'            => array(
321
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
322
-                        'filename' => 'event_editor_event_datetimes',
323
-                    ),
324
-                    'event_editor_event_tickets_help_tab'              => array(
325
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
326
-                        'filename' => 'event_editor_event_tickets',
327
-                    ),
328
-                    'event_editor_event_registration_options_help_tab' => array(
329
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
330
-                        'filename' => 'event_editor_event_registration_options',
331
-                    ),
332
-                    'event_editor_tags_categories_help_tab'            => array(
333
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
334
-                        'filename' => 'event_editor_tags_categories',
335
-                    ),
336
-                    'event_editor_questions_registrants_help_tab'      => array(
337
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
338
-                        'filename' => 'event_editor_questions_registrants',
339
-                    ),
340
-                    'event_editor_save_new_event_help_tab'             => array(
341
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
342
-                        'filename' => 'event_editor_save_new_event',
343
-                    ),
344
-                    'event_editor_other_help_tab'                      => array(
345
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
346
-                        'filename' => 'event_editor_other',
347
-                    ),
348
-                ),
349
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
350
-                // 'help_tour'     => array(
351
-                //     'Event_Editor_Help_Tour',
352
-                // ),
353
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
354
-                'require_nonce' => false,
355
-            ),
356
-            'edit'                   => array(
357
-                'nav'           => array(
358
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
359
-                    'order'      => 5,
360
-                    'persistent' => false,
361
-                    'url'        => isset($this->_req_data['post'])
362
-                        ? EE_Admin_Page::add_query_args_and_nonce(
363
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
364
-                            $this->_current_page_view_url
365
-                        )
366
-                        : $this->_admin_base_url,
367
-                ),
368
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
369
-                'help_tabs'     => array(
370
-                    'event_editor_help_tab'                            => array(
371
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
372
-                        'filename' => 'event_editor',
373
-                    ),
374
-                    'event_editor_title_richtexteditor_help_tab'       => array(
375
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
376
-                        'filename' => 'event_editor_title_richtexteditor',
377
-                    ),
378
-                    'event_editor_venue_details_help_tab'              => array(
379
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
380
-                        'filename' => 'event_editor_venue_details',
381
-                    ),
382
-                    'event_editor_event_datetimes_help_tab'            => array(
383
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
384
-                        'filename' => 'event_editor_event_datetimes',
385
-                    ),
386
-                    'event_editor_event_tickets_help_tab'              => array(
387
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
388
-                        'filename' => 'event_editor_event_tickets',
389
-                    ),
390
-                    'event_editor_event_registration_options_help_tab' => array(
391
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
392
-                        'filename' => 'event_editor_event_registration_options',
393
-                    ),
394
-                    'event_editor_tags_categories_help_tab'            => array(
395
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
396
-                        'filename' => 'event_editor_tags_categories',
397
-                    ),
398
-                    'event_editor_questions_registrants_help_tab'      => array(
399
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
400
-                        'filename' => 'event_editor_questions_registrants',
401
-                    ),
402
-                    'event_editor_save_new_event_help_tab'             => array(
403
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
404
-                        'filename' => 'event_editor_save_new_event',
405
-                    ),
406
-                    'event_editor_other_help_tab'                      => array(
407
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
408
-                        'filename' => 'event_editor_other',
409
-                    ),
410
-                ),
411
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
412
-                'require_nonce' => false,
413
-            ),
414
-            'default_event_settings' => array(
415
-                'nav'           => array(
416
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
417
-                    'order' => 40,
418
-                ),
419
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
420
-                'labels'        => array(
421
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
422
-                ),
423
-                'help_tabs'     => array(
424
-                    'default_settings_help_tab'        => array(
425
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
426
-                        'filename' => 'events_default_settings',
427
-                    ),
428
-                    'default_settings_status_help_tab' => array(
429
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
430
-                        'filename' => 'events_default_settings_status',
431
-                    ),
432
-                    'default_maximum_tickets_help_tab' => array(
433
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
434
-                        'filename' => 'events_default_settings_max_tickets',
435
-                    ),
436
-                ),
437
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
438
-                // 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
439
-                'require_nonce' => false,
440
-            ),
441
-            // template settings
442
-            'template_settings'      => array(
443
-                'nav'           => array(
444
-                    'label' => esc_html__('Templates', 'event_espresso'),
445
-                    'order' => 30,
446
-                ),
447
-                'metaboxes'     => $this->_default_espresso_metaboxes,
448
-                'help_tabs'     => array(
449
-                    'general_settings_templates_help_tab' => array(
450
-                        'title'    => esc_html__('Templates', 'event_espresso'),
451
-                        'filename' => 'general_settings_templates',
452
-                    ),
453
-                ),
454
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
455
-                // 'help_tour'     => array('Templates_Help_Tour'),
456
-                'require_nonce' => false,
457
-            ),
458
-            // event category stuff
459
-            'add_category'           => array(
460
-                'nav'           => array(
461
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
462
-                    'order'      => 15,
463
-                    'persistent' => false,
464
-                ),
465
-                'help_tabs'     => array(
466
-                    'add_category_help_tab' => array(
467
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
468
-                        'filename' => 'events_add_category',
469
-                    ),
470
-                ),
471
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
472
-                // 'help_tour'     => array('Event_Add_Category_Help_Tour'),
473
-                'metaboxes'     => array('_publish_post_box'),
474
-                'require_nonce' => false,
475
-            ),
476
-            'edit_category'          => array(
477
-                'nav'           => array(
478
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
479
-                    'order'      => 15,
480
-                    'persistent' => false,
481
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
482
-                        ? add_query_arg(
483
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
484
-                            $this->_current_page_view_url
485
-                        )
486
-                        : $this->_admin_base_url,
487
-                ),
488
-                'help_tabs'     => array(
489
-                    'edit_category_help_tab' => array(
490
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
491
-                        'filename' => 'events_edit_category',
492
-                    ),
493
-                ),
494
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
495
-                'metaboxes'     => array('_publish_post_box'),
496
-                'require_nonce' => false,
497
-            ),
498
-            'category_list'          => array(
499
-                'nav'           => array(
500
-                    'label' => esc_html__('Categories', 'event_espresso'),
501
-                    'order' => 20,
502
-                ),
503
-                'list_table'    => 'Event_Categories_Admin_List_Table',
504
-                'help_tabs'     => array(
505
-                    'events_categories_help_tab'                       => array(
506
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
507
-                        'filename' => 'events_categories',
508
-                    ),
509
-                    'events_categories_table_column_headings_help_tab' => array(
510
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
511
-                        'filename' => 'events_categories_table_column_headings',
512
-                    ),
513
-                    'events_categories_view_help_tab'                  => array(
514
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
515
-                        'filename' => 'events_categories_views',
516
-                    ),
517
-                    'events_categories_other_help_tab'                 => array(
518
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
519
-                        'filename' => 'events_categories_other',
520
-                    ),
521
-                ),
522
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
523
-                // 'help_tour'     => array(
524
-                //     'Event_Categories_Help_Tour',
525
-                // ),
526
-                'metaboxes'     => $this->_default_espresso_metaboxes,
527
-                'require_nonce' => false,
528
-            ),
529
-            'preview_deletion'           => array(
530
-                'nav'           => array(
531
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
532
-                    'order'      => 15,
533
-                    'persistent' => false,
534
-                    'url'        => '',
535
-                ),
536
-                'require_nonce' => false
537
-            )
538
-        );
539
-    }
540
-
541
-
542
-    /**
543
-     * Used to register any global screen options if necessary for every route in this admin page group.
544
-     */
545
-    protected function _add_screen_options()
546
-    {
547
-    }
548
-
549
-
550
-    /**
551
-     * Implementing the screen options for the 'default' route.
552
-     */
553
-    protected function _add_screen_options_default()
554
-    {
555
-        $this->_per_page_screen_option();
556
-    }
557
-
558
-
559
-    /**
560
-     * Implementing screen options for the category list route.
561
-     */
562
-    protected function _add_screen_options_category_list()
563
-    {
564
-        $page_title = $this->_admin_page_title;
565
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
566
-        $this->_per_page_screen_option();
567
-        $this->_admin_page_title = $page_title;
568
-    }
569
-
570
-
571
-    /**
572
-     * Used to register any global feature pointers for the admin page group.
573
-     */
574
-    protected function _add_feature_pointers()
575
-    {
576
-    }
577
-
578
-
579
-    /**
580
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
581
-     */
582
-    public function load_scripts_styles()
583
-    {
584
-        wp_register_style(
585
-            'events-admin-css',
586
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
587
-            array(),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591
-        wp_enqueue_style('events-admin-css');
592
-        wp_enqueue_style('ee-cat-admin');
593
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
594
-        // registers for all views
595
-        // scripts
596
-        wp_register_script(
597
-            'event_editor_js',
598
-            EVENTS_ASSETS_URL . 'event_editor.js',
599
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
600
-            EVENT_ESPRESSO_VERSION,
601
-            true
602
-        );
603
-    }
604
-
605
-
606
-    /**
607
-     * Enqueuing scripts and styles specific to this view
608
-     */
609
-    public function load_scripts_styles_create_new()
610
-    {
611
-        $this->load_scripts_styles_edit();
612
-    }
613
-
614
-
615
-    /**
616
-     * Enqueuing scripts and styles specific to this view
617
-     */
618
-    public function load_scripts_styles_edit()
619
-    {
620
-        // styles
621
-        wp_enqueue_style('espresso-ui-theme');
622
-        wp_register_style(
623
-            'event-editor-css',
624
-            EVENTS_ASSETS_URL . 'event-editor.css',
625
-            array('ee-admin-css'),
626
-            EVENT_ESPRESSO_VERSION
627
-        );
628
-        wp_enqueue_style('event-editor-css');
629
-        // scripts
630
-        wp_register_script(
631
-            'event-datetime-metabox',
632
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
633
-            array('event_editor_js', 'ee-datepicker'),
634
-            EVENT_ESPRESSO_VERSION
635
-        );
636
-        wp_enqueue_script('event-datetime-metabox');
637
-    }
638
-
639
-
640
-    /**
641
-     * Populating the _views property for the category list table view.
642
-     */
643
-    protected function _set_list_table_views_category_list()
644
-    {
645
-        $this->_views = array(
646
-            'all' => array(
647
-                'slug'        => 'all',
648
-                'label'       => esc_html__('All', 'event_espresso'),
649
-                'count'       => 0,
650
-                'bulk_action' => array(
651
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
652
-                ),
653
-            ),
654
-        );
655
-    }
656
-
657
-
658
-    /**
659
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
660
-     */
661
-    public function admin_init()
662
-    {
663
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
664
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
665
-            'event_espresso'
666
-        );
667
-    }
668
-
669
-
670
-    /**
671
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
672
-     * group.
673
-     */
674
-    public function admin_notices()
675
-    {
676
-    }
677
-
678
-
679
-    /**
680
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
681
-     * this admin page group.
682
-     */
683
-    public function admin_footer_scripts()
684
-    {
685
-    }
686
-
687
-
688
-    /**
689
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
690
-     * warning (via EE_Error::add_error());
691
-     *
692
-     * @param  EE_Event $event Event object
693
-     * @param string    $req_type
694
-     * @return void
695
-     * @throws EE_Error
696
-     * @access public
697
-     */
698
-    public function verify_event_edit($event = null, $req_type = '')
699
-    {
700
-        // don't need to do this when processing
701
-        if (! empty($req_type)) {
702
-            return;
703
-        }
704
-        // no event?
705
-        if (empty($event)) {
706
-            // set event
707
-            $event = $this->_cpt_model_obj;
708
-        }
709
-        // STILL no event?
710
-        if (! $event instanceof EE_Event) {
711
-            return;
712
-        }
713
-        $orig_status = $event->status();
714
-        // first check if event is active.
715
-        if (
716
-            $orig_status === EEM_Event::cancelled
717
-            || $orig_status === EEM_Event::postponed
718
-            || $event->is_expired()
719
-            || $event->is_inactive()
720
-        ) {
721
-            return;
722
-        }
723
-        // made it here so it IS active... next check that any of the tickets are sold.
724
-        if ($event->is_sold_out(true)) {
725
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
-                EE_Error::add_attention(
727
-                    sprintf(
728
-                        esc_html__(
729
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
730
-                            'event_espresso'
731
-                        ),
732
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
-                    )
734
-                );
735
-            }
736
-            return;
737
-        } elseif ($orig_status === EEM_Event::sold_out) {
738
-            EE_Error::add_attention(
739
-                sprintf(
740
-                    esc_html__(
741
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
742
-                        'event_espresso'
743
-                    ),
744
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
745
-                )
746
-            );
747
-        }
748
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
750
-            return;
751
-        }
752
-        // made it here so show warning
753
-        $this->_edit_event_warning();
754
-    }
755
-
756
-
757
-    /**
758
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
759
-     * When needed, hook this into a EE_Error::add_error() notice.
760
-     *
761
-     * @access protected
762
-     * @return void
763
-     */
764
-    protected function _edit_event_warning()
765
-    {
766
-        // we don't want to add warnings during these requests
767
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
-            return;
769
-        }
770
-        EE_Error::add_attention(
771
-            sprintf(
772
-                esc_html__(
773
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
-                    'event_espresso'
775
-                ),
776
-                '<a class="espresso-help-tab-lnk">',
777
-                '</a>'
778
-            )
779
-        );
780
-    }
781
-
782
-
783
-    /**
784
-     * When a user is creating a new event, notify them if they haven't set their timezone.
785
-     * Otherwise, do the normal logic
786
-     *
787
-     * @return string
788
-     * @throws \EE_Error
789
-     */
790
-    protected function _create_new_cpt_item()
791
-    {
792
-        $has_timezone_string = get_option('timezone_string');
793
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
-            EE_Error::add_attention(
796
-                sprintf(
797
-                    esc_html__(
798
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
799
-                        'event_espresso'
800
-                    ),
801
-                    '<br>',
802
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
-                    . '</select>',
805
-                    '<button class="button button-secondary timezone-submit">',
806
-                    '</button><span class="spinner"></span>'
807
-                ),
808
-                __FILE__,
809
-                __FUNCTION__,
810
-                __LINE__
811
-            );
812
-        }
813
-        return parent::_create_new_cpt_item();
814
-    }
815
-
816
-
817
-    /**
818
-     * Sets the _views property for the default route in this admin page group.
819
-     */
820
-    protected function _set_list_table_views_default()
821
-    {
822
-        $this->_views = array(
823
-            'all'   => array(
824
-                'slug'        => 'all',
825
-                'label'       => esc_html__('View All Events', 'event_espresso'),
826
-                'count'       => 0,
827
-                'bulk_action' => array(
828
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
-                ),
830
-            ),
831
-            'draft' => array(
832
-                'slug'        => 'draft',
833
-                'label'       => esc_html__('Draft', 'event_espresso'),
834
-                'count'       => 0,
835
-                'bulk_action' => array(
836
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
-                ),
838
-            ),
839
-        );
840
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
-            $this->_views['trash'] = array(
842
-                'slug'        => 'trash',
843
-                'label'       => esc_html__('Trash', 'event_espresso'),
844
-                'count'       => 0,
845
-                'bulk_action' => array(
846
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
-                ),
849
-            );
850
-        }
851
-    }
852
-
853
-
854
-    /**
855
-     * Provides the legend item array for the default list table view.
856
-     *
857
-     * @return array
858
-     */
859
-    protected function _event_legend_items()
860
-    {
861
-        $items = array(
862
-            'view_details'   => array(
863
-                'class' => 'dashicons dashicons-search',
864
-                'desc'  => esc_html__('View Event', 'event_espresso'),
865
-            ),
866
-            'edit_event'     => array(
867
-                'class' => 'ee-icon ee-icon-calendar-edit',
868
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
-            ),
870
-            'view_attendees' => array(
871
-                'class' => 'dashicons dashicons-groups',
872
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
-            ),
874
-        );
875
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
-        $statuses = array(
877
-            'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
-            ),
881
-            'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
-            ),
885
-            'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
-            ),
889
-            'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
-            ),
893
-            'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
-            ),
897
-            'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
-            ),
901
-            'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
-            ),
905
-        );
906
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
-        return array_merge($items, $statuses);
908
-    }
909
-
910
-
911
-    /**
912
-     * @return EEM_Event
913
-     */
914
-    private function _event_model()
915
-    {
916
-        if (! $this->_event_model instanceof EEM_Event) {
917
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
918
-        }
919
-        return $this->_event_model;
920
-    }
921
-
922
-
923
-    /**
924
-     * Adds extra buttons to the WP CPT permalink field row.
925
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
-     *
927
-     * @param  string $return    the current html
928
-     * @param  int    $id        the post id for the page
929
-     * @param  string $new_title What the title is
930
-     * @param  string $new_slug  what the slug is
931
-     * @return string            The new html string for the permalink area
932
-     */
933
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
-    {
935
-        // make sure this is only when editing
936
-        if (! empty($id)) {
937
-            $post = get_post($id);
938
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
-                       . esc_html__('Shortcode', 'event_espresso')
940
-                       . '</a> ';
941
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
-                       . $post->ID
943
-                       . ']">';
944
-        }
945
-        return $return;
946
-    }
947
-
948
-
949
-    /**
950
-     * _events_overview_list_table
951
-     * This contains the logic for showing the events_overview list
952
-     *
953
-     * @access protected
954
-     * @return void
955
-     * @throws \EE_Error
956
-     */
957
-    protected function _events_overview_list_table()
958
-    {
959
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
-            ? (array) $this->_template_args['after_list_table']
962
-            : array();
963
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
-                . EEH_Template::get_button_or_link(
965
-                    get_post_type_archive_link('espresso_events'),
966
-                    esc_html__("View Event Archive Page", "event_espresso"),
967
-                    'button'
968
-                );
969
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
-            'create_new',
972
-            'add',
973
-            array(),
974
-            'add-new-h2'
975
-        );
976
-        $this->display_admin_list_table_page_with_no_sidebar();
977
-    }
978
-
979
-
980
-    /**
981
-     * this allows for extra misc actions in the default WP publish box
982
-     *
983
-     * @return void
984
-     */
985
-    public function extra_misc_actions_publish_box()
986
-    {
987
-        $this->_generate_publish_box_extra_content();
988
-    }
989
-
990
-
991
-    /**
992
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
-     * saved.
994
-     * Typically you would use this to save any additional data.
995
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
-     * ALSO very important.  When a post transitions from scheduled to published,
997
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
-     * other meta saves. So MAKE sure that you handle this accordingly.
999
-     *
1000
-     * @access protected
1001
-     * @abstract
1002
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
-     * @param  object $post    The post object of the cpt that was saved.
1004
-     * @return void
1005
-     * @throws \EE_Error
1006
-     */
1007
-    protected function _insert_update_cpt_item($post_id, $post)
1008
-    {
1009
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
-            // get out we're not processing an event save.
1011
-            return;
1012
-        }
1013
-        $event_values = array(
1014
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
-            'EVT_additional_limit'            => min(
1017
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
-            ),
1020
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
-                ? $this->_req_data['EVT_default_registration_status']
1022
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
-                ? $this->_req_data['timezone_string'] : null,
1027
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
-                ? $this->_req_data['externalURL'] : null,
1029
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
-                ? $this->_req_data['event_phone'] : null,
1031
-        );
1032
-        // update event
1033
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
-        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1035
-        $get_one_where = array(
1036
-            $this->_event_model()->primary_key_name() => $post_id,
1037
-            'OR'                                      => array(
1038
-                'status'   => $post->post_status,
1039
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
-                // but the returned object here has a status of "publish", so use the original post status as well
1041
-                'status*1' => $this->_req_data['original_post_status'],
1042
-            ),
1043
-        );
1044
-        $event = $this->_event_model()->get_one(array($get_one_where));
1045
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
-        $event_update_callbacks = apply_filters(
1047
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
-            array(
1049
-                array($this, '_default_venue_update'),
1050
-                array($this, '_default_tickets_update'),
1051
-            )
1052
-        );
1053
-        $att_success = true;
1054
-        foreach ($event_update_callbacks as $e_callback) {
1055
-            $_success = is_callable($e_callback)
1056
-                ? call_user_func($e_callback, $event, $this->_req_data)
1057
-                : false;
1058
-            // if ANY of these updates fail then we want the appropriate global error message
1059
-            $att_success = ! $att_success ? $att_success : $_success;
1060
-        }
1061
-        // any errors?
1062
-        if ($success && false === $att_success) {
1063
-            EE_Error::add_error(
1064
-                esc_html__(
1065
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1066
-                    'event_espresso'
1067
-                ),
1068
-                __FILE__,
1069
-                __FUNCTION__,
1070
-                __LINE__
1071
-            );
1072
-        } elseif ($success === false) {
1073
-            EE_Error::add_error(
1074
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
-                __FILE__,
1076
-                __FUNCTION__,
1077
-                __LINE__
1078
-            );
1079
-        }
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * @see parent::restore_item()
1085
-     * @param int $post_id
1086
-     * @param int $revision_id
1087
-     */
1088
-    protected function _restore_cpt_item($post_id, $revision_id)
1089
-    {
1090
-        // copy existing event meta to new post
1091
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
-        if ($post_evt instanceof EE_Event) {
1093
-            // meta revision restore
1094
-            $post_evt->restore_revision($revision_id);
1095
-            // related objs restore
1096
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
-        }
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Attach the venue to the Event
1103
-     *
1104
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1105
-     * @param  array     $data   The request data from the form
1106
-     * @return bool           Success or fail.
1107
-     */
1108
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
-    {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1112
-        $rows_affected = null;
1113
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
-        // very important.  If we don't have a venue name...
1115
-        // then we'll get out because not necessary to create empty venue
1116
-        if (empty($data['venue_title'])) {
1117
-            return false;
1118
-        }
1119
-        $venue_array = array(
1120
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
-                : null,
1126
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
-            'status'              => 'publish',
1139
-        );
1140
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1142
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1143
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1144
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1145
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1146
-            return $rows_affected > 0 ? true : false;
1147
-        } else {
1148
-            // we insert the venue
1149
-            $venue_id = $venue_model->insert($venue_array);
1150
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1151
-            return ! empty($venue_id) ? true : false;
1152
-        }
1153
-        // when we have the ancestor come in it's already been handled by the revision save.
1154
-    }
1155
-
1156
-
1157
-    /**
1158
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
-     *
1160
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1161
-     * @param  array    $data   The request data from the form
1162
-     * @return array
1163
-     */
1164
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
-    {
1166
-        $success = true;
1167
-        $saved_dtt = null;
1168
-        $saved_tickets = array();
1169
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1170
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
-            // trim all values to ensure any excess whitespace is removed.
1172
-            $dtt = array_map('trim', $dtt);
1173
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
-                : $dtt['DTT_EVT_start'];
1175
-            $datetime_values = array(
1176
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
-                'DTT_order'     => $row,
1181
-            );
1182
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1184
-                $DTM = EE_Registry::instance()
1185
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1187
-                $DTM->set_date_format($incoming_date_formats[0]);
1188
-                $DTM->set_time_format($incoming_date_formats[1]);
1189
-                foreach ($datetime_values as $field => $value) {
1190
-                    $DTM->set($field, $value);
1191
-                }
1192
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1194
-            } else {
1195
-                $DTM = EE_Registry::instance()->load_class(
1196
-                    'Datetime',
1197
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
-                    false,
1199
-                    false
1200
-                );
1201
-                foreach ($datetime_values as $field => $value) {
1202
-                    $DTM->set($field, $value);
1203
-                }
1204
-            }
1205
-            $DTM->save();
1206
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
-            // load DTT helper
1208
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
-                $DTT->save();
1213
-            }
1214
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
-            $saved_dtt = $DTT;
1216
-            $success = ! $success ? $success : $DTT;
1217
-            // if ANY of these updates fail then we want the appropriate global error message.
1218
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1219
-        }
1220
-        // no dtts get deleted so we don't do any of that logic here.
1221
-        // update tickets next
1222
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1224
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1225
-            $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
-            // trim inputs to ensure any excess whitespace is removed.
1229
-            $tkt = array_map('trim', $tkt);
1230
-            if (empty($tkt['TKT_start_date'])) {
1231
-                // let's use now in the set timezone.
1232
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
-            }
1235
-            if (empty($tkt['TKT_end_date'])) {
1236
-                // use the start date of the first datetime
1237
-                $dtt = $evtobj->first_datetime();
1238
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
-                    $incoming_date_formats[0],
1240
-                    $incoming_date_formats[1]
1241
-                );
1242
-            }
1243
-            $TKT_values = array(
1244
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1249
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1250
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
-                'TKT_row'         => $row,
1255
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
-                'TKT_price'       => $ticket_price,
1257
-            );
1258
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
-                $TKT_values['TKT_ID'] = 0;
1261
-                $TKT_values['TKT_is_default'] = 0;
1262
-                $TKT_values['TKT_price'] = $ticket_price;
1263
-                $update_prices = true;
1264
-            }
1265
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1269
-                $TKT = EE_Registry::instance()
1270
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1272
-                if ($TKT instanceof EE_Ticket) {
1273
-                    $ticket_sold = $TKT->count_related(
1274
-                        'Registration',
1275
-                        array(
1276
-                            array(
1277
-                                'STS_ID' => array(
1278
-                                    'NOT IN',
1279
-                                    array(EEM_Registration::status_id_incomplete),
1280
-                                ),
1281
-                            ),
1282
-                        )
1283
-                    ) > 0 ? true : false;
1284
-                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
-                                      && ! $TKT->get('TKT_deleted');
1287
-                    $TKT->set_date_format($incoming_date_formats[0]);
1288
-                    $TKT->set_time_format($incoming_date_formats[1]);
1289
-                    // set new values
1290
-                    foreach ($TKT_values as $field => $value) {
1291
-                        if ($field == 'TKT_qty') {
1292
-                            $TKT->set_qty($value);
1293
-                        } else {
1294
-                            $TKT->set($field, $value);
1295
-                        }
1296
-                    }
1297
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
-                    if ($create_new_TKT) {
1299
-                        // archive the old ticket first
1300
-                        $TKT->set('TKT_deleted', 1);
1301
-                        $TKT->save();
1302
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1304
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
-                        $TKT = clone $TKT;
1306
-                        $TKT->set('TKT_ID', 0);
1307
-                        $TKT->set('TKT_deleted', 0);
1308
-                        $TKT->set('TKT_price', $ticket_price);
1309
-                        $TKT->set('TKT_sold', 0);
1310
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1311
-                        $update_prices = true;
1312
-                    }
1313
-                    // make sure price is set if it hasn't been already
1314
-                    $TKT->set('TKT_price', $ticket_price);
1315
-                }
1316
-            } else {
1317
-                // no TKT_id so a new TKT
1318
-                $TKT_values['TKT_price'] = $ticket_price;
1319
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
-                if ($TKT instanceof EE_Ticket) {
1321
-                    // need to reset values to properly account for the date formats
1322
-                    $TKT->set_date_format($incoming_date_formats[0]);
1323
-                    $TKT->set_time_format($incoming_date_formats[1]);
1324
-                    $TKT->set_timezone($evtobj->get_timezone());
1325
-                    // set new values
1326
-                    foreach ($TKT_values as $field => $value) {
1327
-                        if ($field == 'TKT_qty') {
1328
-                            $TKT->set_qty($value);
1329
-                        } else {
1330
-                            $TKT->set($field, $value);
1331
-                        }
1332
-                    }
1333
-                    $update_prices = true;
1334
-                }
1335
-            }
1336
-            // cap ticket qty by datetime reg limits
1337
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
-            // update ticket.
1339
-            $TKT->save();
1340
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
-                $TKT->save();
1345
-            }
1346
-            // initially let's add the ticket to the dtt
1347
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1349
-            // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
-        }
1352
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
-        foreach ($tickets_removed as $id) {
1356
-            $id = absint($id);
1357
-            // get the ticket for this id
1358
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
-            if ( ! $tkt_to_remove instanceof EE_Ticket) {
1360
-                continue;
1361
-            }
1362
-
1363
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1364
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1365
-            foreach ($dtts as $dtt) {
1366
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1367
-            }
1368
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1369
-            $tkt_to_remove->delete_related_permanently('Price');
1370
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1371
-            $tkt_to_remove->delete_permanently();
1372
-        }
1373
-        return array($saved_dtt, $saved_tickets);
1374
-    }
1375
-
1376
-
1377
-    /**
1378
-     * This attaches a list of given prices to a ticket.
1379
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1380
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1381
-     * price info and prices are automatically "archived" via the ticket.
1382
-     *
1383
-     * @access  private
1384
-     * @param array     $prices     Array of prices from the form.
1385
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1386
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1387
-     * @return  void
1388
-     */
1389
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1390
-    {
1391
-        foreach ($prices as $row => $prc) {
1392
-            $PRC_values = array(
1393
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1394
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1395
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1396
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1397
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1398
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1399
-                'PRC_order'      => $row,
1400
-            );
1401
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1402
-                $PRC_values['PRC_ID'] = 0;
1403
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1404
-            } else {
1405
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1406
-                // update this price with new values
1407
-                foreach ($PRC_values as $field => $newprc) {
1408
-                    $PRC->set($field, $newprc);
1409
-                }
1410
-                $PRC->save();
1411
-            }
1412
-            $ticket->_add_relation_to($PRC, 'Price');
1413
-        }
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * Add in our autosave ajax handlers
1419
-     *
1420
-     */
1421
-    protected function _ee_autosave_create_new()
1422
-    {
1423
-    }
1424
-
1425
-
1426
-    /**
1427
-     * More autosave handlers.
1428
-     */
1429
-    protected function _ee_autosave_edit()
1430
-    {
1431
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1432
-    }
1433
-
1434
-
1435
-    /**
1436
-     *    _generate_publish_box_extra_content
1437
-     */
1438
-    private function _generate_publish_box_extra_content()
1439
-    {
1440
-        // load formatter helper
1441
-        // args for getting related registrations
1442
-        $approved_query_args = array(
1443
-            array(
1444
-                'REG_deleted' => 0,
1445
-                'STS_ID'      => EEM_Registration::status_id_approved,
1446
-            ),
1447
-        );
1448
-        $not_approved_query_args = array(
1449
-            array(
1450
-                'REG_deleted' => 0,
1451
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1452
-            ),
1453
-        );
1454
-        $pending_payment_query_args = array(
1455
-            array(
1456
-                'REG_deleted' => 0,
1457
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1458
-            ),
1459
-        );
1460
-        // publish box
1461
-        $publish_box_extra_args = array(
1462
-            'view_approved_reg_url'        => add_query_arg(
1463
-                array(
1464
-                    'action'      => 'default',
1465
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1466
-                    '_reg_status' => EEM_Registration::status_id_approved,
1467
-                ),
1468
-                REG_ADMIN_URL
1469
-            ),
1470
-            'view_not_approved_reg_url'    => add_query_arg(
1471
-                array(
1472
-                    'action'      => 'default',
1473
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1474
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1475
-                ),
1476
-                REG_ADMIN_URL
1477
-            ),
1478
-            'view_pending_payment_reg_url' => add_query_arg(
1479
-                array(
1480
-                    'action'      => 'default',
1481
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1482
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1483
-                ),
1484
-                REG_ADMIN_URL
1485
-            ),
1486
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1487
-                'Registration',
1488
-                $approved_query_args
1489
-            ),
1490
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1491
-                'Registration',
1492
-                $not_approved_query_args
1493
-            ),
1494
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1495
-                'Registration',
1496
-                $pending_payment_query_args
1497
-            ),
1498
-            'misc_pub_section_class'       => apply_filters(
1499
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1500
-                'misc-pub-section'
1501
-            ),
1502
-        );
1503
-        ob_start();
1504
-        do_action(
1505
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1506
-            $this->_cpt_model_obj
1507
-        );
1508
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1509
-        // load template
1510
-        EEH_Template::display_template(
1511
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1512
-            $publish_box_extra_args
1513
-        );
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * @return EE_Event
1519
-     */
1520
-    public function get_event_object()
1521
-    {
1522
-        return $this->_cpt_model_obj;
1523
-    }
1524
-
1525
-
1526
-
1527
-
1528
-    /** METABOXES * */
1529
-    /**
1530
-     * _register_event_editor_meta_boxes
1531
-     * add all metaboxes related to the event_editor
1532
-     *
1533
-     * @return void
1534
-     */
1535
-    protected function _register_event_editor_meta_boxes()
1536
-    {
1537
-        $this->verify_cpt_object();
1538
-        add_meta_box(
1539
-            'espresso_event_editor_tickets',
1540
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1541
-            array($this, 'ticket_metabox'),
1542
-            $this->page_slug,
1543
-            'normal',
1544
-            'high'
1545
-        );
1546
-        add_meta_box(
1547
-            'espresso_event_editor_event_options',
1548
-            esc_html__('Event Registration Options', 'event_espresso'),
1549
-            array($this, 'registration_options_meta_box'),
1550
-            $this->page_slug,
1551
-            'side',
1552
-            'default'
1553
-        );
1554
-        // NOTE: if you're looking for other metaboxes in here,
1555
-        // where a metabox has a related management page in the admin
1556
-        // you will find it setup in the related management page's "_Hooks" file.
1557
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1558
-    }
1559
-
1560
-
1561
-    /**
1562
-     * @throws DomainException
1563
-     * @throws EE_Error
1564
-     */
1565
-    public function ticket_metabox()
1566
-    {
1567
-        $existing_datetime_ids = $existing_ticket_ids = array();
1568
-        // defaults for template args
1569
-        $template_args = array(
1570
-            'existing_datetime_ids'    => '',
1571
-            'event_datetime_help_link' => '',
1572
-            'ticket_options_help_link' => '',
1573
-            'time'                     => null,
1574
-            'ticket_rows'              => '',
1575
-            'existing_ticket_ids'      => '',
1576
-            'total_ticket_rows'        => 1,
1577
-            'ticket_js_structure'      => '',
1578
-            'trash_icon'               => 'ee-lock-icon',
1579
-            'disabled'                 => '',
1580
-        );
1581
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1582
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1583
-        /**
1584
-         * 1. Start with retrieving Datetimes
1585
-         * 2. Fore each datetime get related tickets
1586
-         * 3. For each ticket get related prices
1587
-         */
1588
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1589
-        /** @type EE_Datetime $first_datetime */
1590
-        $first_datetime = reset($times);
1591
-        // do we get related tickets?
1592
-        if (
1593
-            $first_datetime instanceof EE_Datetime
1594
-            && $first_datetime->ID() !== 0
1595
-        ) {
1596
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1597
-            $template_args['time'] = $first_datetime;
1598
-            $related_tickets = $first_datetime->tickets(
1599
-                array(
1600
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1601
-                    'default_where_conditions' => 'none',
1602
-                )
1603
-            );
1604
-            if (! empty($related_tickets)) {
1605
-                $template_args['total_ticket_rows'] = count($related_tickets);
1606
-                $row = 0;
1607
-                foreach ($related_tickets as $ticket) {
1608
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1609
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1610
-                    $row++;
1611
-                }
1612
-            } else {
1613
-                $template_args['total_ticket_rows'] = 1;
1614
-                /** @type EE_Ticket $ticket */
1615
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1616
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1617
-            }
1618
-        } else {
1619
-            $template_args['time'] = $times[0];
1620
-            /** @type EE_Ticket $ticket */
1621
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1622
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1623
-            // NOTE: we're just sending the first default row
1624
-            // (decaf can't manage default tickets so this should be sufficient);
1625
-        }
1626
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1627
-            'event_editor_event_datetimes_help_tab'
1628
-        );
1629
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1630
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1631
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1632
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1633
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1634
-            true
1635
-        );
1636
-        $template = apply_filters(
1637
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1638
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1639
-        );
1640
-        EEH_Template::display_template($template, $template_args);
1641
-    }
1642
-
1643
-
1644
-    /**
1645
-     * Setup an individual ticket form for the decaf event editor page
1646
-     *
1647
-     * @access private
1648
-     * @param  EE_Ticket $ticket   the ticket object
1649
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1650
-     * @param int        $row
1651
-     * @return string generated html for the ticket row.
1652
-     */
1653
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1654
-    {
1655
-        $template_args = array(
1656
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1657
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1658
-                : '',
1659
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1660
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1661
-            'TKT_name'            => $ticket->get('TKT_name'),
1662
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1663
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1664
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1665
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1666
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1667
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1668
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1669
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1670
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1671
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1672
-                : ' disabled=disabled',
1673
-        );
1674
-        $price = $ticket->ID() !== 0
1675
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1676
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1677
-        $price_args = array(
1678
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1679
-            'PRC_amount'            => $price->get('PRC_amount'),
1680
-            'PRT_ID'                => $price->get('PRT_ID'),
1681
-            'PRC_ID'                => $price->get('PRC_ID'),
1682
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1683
-        );
1684
-        // make sure we have default start and end dates if skeleton
1685
-        // handle rows that should NOT be empty
1686
-        if (empty($template_args['TKT_start_date'])) {
1687
-            // if empty then the start date will be now.
1688
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1689
-        }
1690
-        if (empty($template_args['TKT_end_date'])) {
1691
-            // get the earliest datetime (if present);
1692
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1693
-                ? $this->_cpt_model_obj->get_first_related(
1694
-                    'Datetime',
1695
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1696
-                )
1697
-                : null;
1698
-            if (! empty($earliest_dtt)) {
1699
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1700
-            } else {
1701
-                $template_args['TKT_end_date'] = date(
1702
-                    'Y-m-d h:i a',
1703
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1704
-                );
1705
-            }
1706
-        }
1707
-        $template_args = array_merge($template_args, $price_args);
1708
-        $template = apply_filters(
1709
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1710
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1711
-            $ticket
1712
-        );
1713
-        return EEH_Template::display_template($template, $template_args, true);
1714
-    }
1715
-
1716
-
1717
-    /**
1718
-     * @throws DomainException
1719
-     */
1720
-    public function registration_options_meta_box()
1721
-    {
1722
-        $yes_no_values = array(
1723
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1724
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1725
-        );
1726
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1727
-            array(
1728
-                EEM_Registration::status_id_cancelled,
1729
-                EEM_Registration::status_id_declined,
1730
-                EEM_Registration::status_id_incomplete,
1731
-            ),
1732
-            true
1733
-        );
1734
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1735
-        $template_args['_event'] = $this->_cpt_model_obj;
1736
-        $template_args['event'] = $this->_cpt_model_obj;
1737
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1738
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1739
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1740
-            'default_reg_status',
1741
-            $default_reg_status_values,
1742
-            $this->_cpt_model_obj->default_registration_status()
1743
-        );
1744
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1745
-            'display_desc',
1746
-            $yes_no_values,
1747
-            $this->_cpt_model_obj->display_description()
1748
-        );
1749
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1750
-            'display_ticket_selector',
1751
-            $yes_no_values,
1752
-            $this->_cpt_model_obj->display_ticket_selector(),
1753
-            '',
1754
-            '',
1755
-            false
1756
-        );
1757
-        $template_args['additional_registration_options'] = apply_filters(
1758
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1759
-            '',
1760
-            $template_args,
1761
-            $yes_no_values,
1762
-            $default_reg_status_values
1763
-        );
1764
-        EEH_Template::display_template(
1765
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1766
-            $template_args
1767
-        );
1768
-    }
1769
-
1770
-
1771
-    /**
1772
-     * _get_events()
1773
-     * This method simply returns all the events (for the given _view and paging)
1774
-     *
1775
-     * @access public
1776
-     * @param int  $per_page     count of items per page (20 default);
1777
-     * @param int  $current_page what is the current page being viewed.
1778
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1779
-     *                           If FALSE then we return an array of event objects
1780
-     *                           that match the given _view and paging parameters.
1781
-     * @return array an array of event objects.
1782
-     */
1783
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1784
-    {
1785
-        $EEME = $this->_event_model();
1786
-        $offset = ($current_page - 1) * $per_page;
1787
-        $limit = $count ? null : $offset . ',' . $per_page;
1788
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1789
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1790
-        if (isset($this->_req_data['month_range'])) {
1791
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1792
-            // simulate the FIRST day of the month, that fixes issues for months like February
1793
-            // where PHP doesn't know what to assume for date.
1794
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1795
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1796
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1797
-        }
1798
-        $where = array();
1799
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1800
-        // determine what post_status our condition will have for the query.
1801
-        switch ($status) {
1802
-            case 'month':
1803
-            case 'today':
1804
-            case null:
1805
-            case 'all':
1806
-                break;
1807
-            case 'draft':
1808
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1809
-                break;
1810
-            default:
1811
-                $where['status'] = $status;
1812
-        }
1813
-        // categories?
1814
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1815
-            ? $this->_req_data['EVT_CAT'] : null;
1816
-        if (! empty($category)) {
1817
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1818
-            $where['Term_Taxonomy.term_id'] = $category;
1819
-        }
1820
-        // date where conditions
1821
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1822
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1823
-            $DateTime = new DateTime(
1824
-                $year_r . '-' . $month_r . '-01 00:00:00',
1825
-                new DateTimeZone('UTC')
1826
-            );
1827
-            $start = $DateTime->getTimestamp();
1828
-            // set the datetime to be the end of the month
1829
-            $DateTime->setDate(
1830
-                $year_r,
1831
-                $month_r,
1832
-                $DateTime->format('t')
1833
-            )->setTime(23, 59, 59);
1834
-            $end = $DateTime->getTimestamp();
1835
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1836
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1837
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1838
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1839
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1840
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1841
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1842
-            $now = date('Y-m-01');
1843
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1844
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1845
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1846
-                            ->setTime(23, 59, 59)
1847
-                            ->format(implode(' ', $start_formats));
1848
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1849
-        }
1850
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1851
-            $where['EVT_wp_user'] = get_current_user_id();
1852
-        } else {
1853
-            if (! isset($where['status'])) {
1854
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1855
-                    $where['OR'] = array(
1856
-                        'status*restrict_private' => array('!=', 'private'),
1857
-                        'AND'                     => array(
1858
-                            'status*inclusive' => array('=', 'private'),
1859
-                            'EVT_wp_user'      => get_current_user_id(),
1860
-                        ),
1861
-                    );
1862
-                }
1863
-            }
1864
-        }
1865
-        if (isset($this->_req_data['EVT_wp_user'])) {
1866
-            if (
1867
-                $this->_req_data['EVT_wp_user'] != get_current_user_id()
1868
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1869
-            ) {
1870
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1871
-            }
1872
-        }
1873
-        // search query handling
1874
-        if (isset($this->_req_data['s'])) {
1875
-            $search_string = '%' . $this->_req_data['s'] . '%';
1876
-            $where['OR'] = array(
1877
-                'EVT_name'       => array('LIKE', $search_string),
1878
-                'EVT_desc'       => array('LIKE', $search_string),
1879
-                'EVT_short_desc' => array('LIKE', $search_string),
1880
-            );
1881
-        }
1882
-        // filter events by venue.
1883
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1884
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1885
-        }
1886
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1887
-        $query_params = apply_filters(
1888
-            'FHEE__Events_Admin_Page__get_events__query_params',
1889
-            array(
1890
-                $where,
1891
-                'limit'    => $limit,
1892
-                'order_by' => $orderby,
1893
-                'order'    => $order,
1894
-                'group_by' => 'EVT_ID',
1895
-            ),
1896
-            $this->_req_data
1897
-        );
1898
-
1899
-        // let's first check if we have special requests coming in.
1900
-        if (isset($this->_req_data['active_status'])) {
1901
-            switch ($this->_req_data['active_status']) {
1902
-                case 'upcoming':
1903
-                    return $EEME->get_upcoming_events($query_params, $count);
1904
-                    break;
1905
-                case 'expired':
1906
-                    return $EEME->get_expired_events($query_params, $count);
1907
-                    break;
1908
-                case 'active':
1909
-                    return $EEME->get_active_events($query_params, $count);
1910
-                    break;
1911
-                case 'inactive':
1912
-                    return $EEME->get_inactive_events($query_params, $count);
1913
-                    break;
1914
-            }
1915
-        }
1916
-
1917
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1918
-        return $events;
1919
-    }
1920
-
1921
-
1922
-    /**
1923
-     * handling for WordPress CPT actions (trash, restore, delete)
1924
-     *
1925
-     * @param string $post_id
1926
-     */
1927
-    public function trash_cpt_item($post_id)
1928
-    {
1929
-        $this->_req_data['EVT_ID'] = $post_id;
1930
-        $this->_trash_or_restore_event('trash', false);
1931
-    }
1932
-
1933
-
1934
-    /**
1935
-     * @param string $post_id
1936
-     */
1937
-    public function restore_cpt_item($post_id)
1938
-    {
1939
-        $this->_req_data['EVT_ID'] = $post_id;
1940
-        $this->_trash_or_restore_event('draft', false);
1941
-    }
1942
-
1943
-
1944
-    /**
1945
-     * @param string $post_id
1946
-     */
1947
-    public function delete_cpt_item($post_id)
1948
-    {
1949
-        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1950
-        $this->_req_data['EVT_ID'] = $post_id;
1951
-        $this->_delete_event();
1952
-    }
1953
-
1954
-
1955
-    /**
1956
-     * _trash_or_restore_event
1957
-     *
1958
-     * @access protected
1959
-     * @param  string $event_status
1960
-     * @param bool    $redirect_after
1961
-     */
1962
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1963
-    {
1964
-        // determine the event id and set to array.
1965
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1966
-        // loop thru events
1967
-        if ($EVT_ID) {
1968
-            // clean status
1969
-            $event_status = sanitize_key($event_status);
1970
-            // grab status
1971
-            if (! empty($event_status)) {
1972
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1973
-            } else {
1974
-                $success = false;
1975
-                $msg = esc_html__(
1976
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1977
-                    'event_espresso'
1978
-                );
1979
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1980
-            }
1981
-        } else {
1982
-            $success = false;
1983
-            $msg = esc_html__(
1984
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1985
-                'event_espresso'
1986
-            );
1987
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1988
-        }
1989
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1990
-        if ($redirect_after) {
1991
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1992
-        }
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * _trash_or_restore_events
1998
-     *
1999
-     * @access protected
2000
-     * @param  string $event_status
2001
-     * @return void
2002
-     */
2003
-    protected function _trash_or_restore_events($event_status = 'trash')
2004
-    {
2005
-        // clean status
2006
-        $event_status = sanitize_key($event_status);
2007
-        // grab status
2008
-        if (! empty($event_status)) {
2009
-            $success = true;
2010
-            // determine the event id and set to array.
2011
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2012
-            // loop thru events
2013
-            foreach ($EVT_IDs as $EVT_ID) {
2014
-                if ($EVT_ID = absint($EVT_ID)) {
2015
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2016
-                    $success = $results !== false ? $success : false;
2017
-                } else {
2018
-                    $msg = sprintf(
2019
-                        esc_html__(
2020
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2021
-                            'event_espresso'
2022
-                        ),
2023
-                        $EVT_ID
2024
-                    );
2025
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2026
-                    $success = false;
2027
-                }
2028
-            }
2029
-        } else {
2030
-            $success = false;
2031
-            $msg = esc_html__(
2032
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2033
-                'event_espresso'
2034
-            );
2035
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2036
-        }
2037
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2038
-        $success = $success ? 2 : false;
2039
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2040
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2041
-    }
2042
-
2043
-
2044
-    /**
2045
-     * _trash_or_restore_events
2046
-     *
2047
-     * @access  private
2048
-     * @param  int    $EVT_ID
2049
-     * @param  string $event_status
2050
-     * @return bool
2051
-     */
2052
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2053
-    {
2054
-        // grab event id
2055
-        if (! $EVT_ID) {
2056
-            $msg = esc_html__(
2057
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2058
-                'event_espresso'
2059
-            );
2060
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2061
-            return false;
2062
-        }
2063
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2064
-        // clean status
2065
-        $event_status = sanitize_key($event_status);
2066
-        // grab status
2067
-        if (empty($event_status)) {
2068
-            $msg = esc_html__(
2069
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2070
-                'event_espresso'
2071
-            );
2072
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2073
-            return false;
2074
-        }
2075
-        // was event trashed or restored ?
2076
-        switch ($event_status) {
2077
-            case 'draft':
2078
-                $action = 'restored from the trash';
2079
-                $hook = 'AHEE_event_restored_from_trash';
2080
-                break;
2081
-            case 'trash':
2082
-                $action = 'moved to the trash';
2083
-                $hook = 'AHEE_event_moved_to_trash';
2084
-                break;
2085
-            default:
2086
-                $action = 'updated';
2087
-                $hook = false;
2088
-        }
2089
-        // use class to change status
2090
-        $this->_cpt_model_obj->set_status($event_status);
2091
-        $success = $this->_cpt_model_obj->save();
2092
-        if ($success === false) {
2093
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2094
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2095
-            return false;
2096
-        }
2097
-        if ($hook) {
2098
-            do_action($hook);
2099
-        }
2100
-        return true;
2101
-    }
2102
-
2103
-
2104
-    /**
2105
-     * _delete_event
2106
-     *
2107
-     * @access protected
2108
-     * @param bool $redirect_after
2109
-     */
2110
-    protected function _delete_event()
2111
-    {
2112
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : array());
2113
-    }
2114
-
2115
-    /**
2116
-     * Gets the tree traversal batch persister.
2117
-     * @since 4.10.12.p
2118
-     * @return NodeGroupDao
2119
-     * @throws InvalidArgumentException
2120
-     * @throws InvalidDataTypeException
2121
-     * @throws InvalidInterfaceException
2122
-     */
2123
-    protected function getModelObjNodeGroupPersister()
2124
-    {
2125
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2126
-            $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2127
-        }
2128
-        return $this->model_obj_node_group_persister;
2129
-    }
2130
-
2131
-    /**
2132
-     * _delete_events
2133
-     *
2134
-     * @access protected
2135
-     * @return void
2136
-     */
2137
-    protected function _delete_events()
2138
-    {
2139
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array());
2140
-    }
2141
-
2142
-    protected function generateDeletionPreview($event_ids)
2143
-    {
2144
-        $event_ids = (array) $event_ids;
2145
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2146
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2147
-        $return_url = EE_Admin_Page::add_query_args_and_nonce(
2148
-            [
2149
-                'action' => 'preview_deletion',
2150
-                'deletion_job_code' => $deletion_job_code,
2151
-            ],
2152
-            $this->_admin_base_url
2153
-        );
2154
-        $event_ids = array_map(
2155
-            'intval',
2156
-            $event_ids
2157
-        );
2158
-
2159
-        EEH_URL::safeRedirectAndExit(
2160
-            EE_Admin_Page::add_query_args_and_nonce(
2161
-                array(
2162
-                    'page'        => 'espresso_batch',
2163
-                    'batch'       => EED_Batch::batch_job,
2164
-                    'EVT_IDs'      => $event_ids,
2165
-                    'deletion_job_code' => $deletion_job_code,
2166
-                    'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2167
-                    'return_url'  => urlencode($return_url),
2168
-                ),
2169
-                admin_url()
2170
-            )
2171
-        );
2172
-    }
2173
-
2174
-    /**
2175
-     * Checks for a POST submission
2176
-     * @since 4.10.12.p
2177
-     */
2178
-    protected function confirmDeletion()
2179
-    {
2180
-        $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2181
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2182
-    }
2183
-
2184
-    /**
2185
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2186
-     * @since 4.10.12.p
2187
-     * @throws EE_Error
2188
-     */
2189
-    protected function previewDeletion()
2190
-    {
2191
-        $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2192
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2193
-        $this->display_admin_page_with_no_sidebar();
2194
-    }
2195
-
2196
-    /**
2197
-     * get total number of events
2198
-     *
2199
-     * @access public
2200
-     * @return int
2201
-     */
2202
-    public function total_events()
2203
-    {
2204
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2205
-        return $count;
2206
-    }
2207
-
2208
-
2209
-    /**
2210
-     * get total number of draft events
2211
-     *
2212
-     * @access public
2213
-     * @return int
2214
-     */
2215
-    public function total_events_draft()
2216
-    {
2217
-        $where = array(
2218
-            'status' => array('IN', array('draft', 'auto-draft')),
2219
-        );
2220
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2221
-        return $count;
2222
-    }
2223
-
2224
-
2225
-    /**
2226
-     * get total number of trashed events
2227
-     *
2228
-     * @access public
2229
-     * @return int
2230
-     */
2231
-    public function total_trashed_events()
2232
-    {
2233
-        $where = array(
2234
-            'status' => 'trash',
2235
-        );
2236
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2237
-        return $count;
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     *    _default_event_settings
2243
-     *    This generates the Default Settings Tab
2244
-     *
2245
-     * @return void
2246
-     * @throws EE_Error
2247
-     */
2248
-    protected function _default_event_settings()
2249
-    {
2250
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2251
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2252
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2253
-        $this->display_admin_page_with_sidebar();
2254
-    }
2255
-
2256
-
2257
-    /**
2258
-     * Return the form for event settings.
2259
-     *
2260
-     * @return EE_Form_Section_Proper
2261
-     * @throws EE_Error
2262
-     */
2263
-    protected function _default_event_settings_form()
2264
-    {
2265
-        $registration_config = EE_Registry::instance()->CFG->registration;
2266
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2267
-            // exclude
2268
-            array(
2269
-                EEM_Registration::status_id_cancelled,
2270
-                EEM_Registration::status_id_declined,
2271
-                EEM_Registration::status_id_incomplete,
2272
-                EEM_Registration::status_id_wait_list,
2273
-            ),
2274
-            true
2275
-        );
2276
-        return new EE_Form_Section_Proper(
2277
-            array(
2278
-                'name'            => 'update_default_event_settings',
2279
-                'html_id'         => 'update_default_event_settings',
2280
-                'html_class'      => 'form-table',
2281
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2282
-                'subsections'     => apply_filters(
2283
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2284
-                    array(
2285
-                        'default_reg_status'  => new EE_Select_Input(
2286
-                            $registration_stati_for_selection,
2287
-                            array(
2288
-                                'default'         => isset($registration_config->default_STS_ID)
2289
-                                                     && array_key_exists(
2290
-                                                         $registration_config->default_STS_ID,
2291
-                                                         $registration_stati_for_selection
2292
-                                                     )
2293
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2294
-                                    : EEM_Registration::status_id_pending_payment,
2295
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2296
-                                                     . EEH_Template::get_help_tab_link(
2297
-                                                         'default_settings_status_help_tab'
2298
-                                                     ),
2299
-                                'html_help_text'  => esc_html__(
2300
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2301
-                                    'event_espresso'
2302
-                                ),
2303
-                            )
2304
-                        ),
2305
-                        'default_max_tickets' => new EE_Integer_Input(
2306
-                            array(
2307
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2308
-                                    ? $registration_config->default_maximum_number_of_tickets
2309
-                                    : EEM_Event::get_default_additional_limit(),
2310
-                                'html_label_text' => esc_html__(
2311
-                                    'Default Maximum Tickets Allowed Per Order:',
2312
-                                    'event_espresso'
2313
-                                )
2314
-                                                     . EEH_Template::get_help_tab_link(
2315
-                                                         'default_maximum_tickets_help_tab"'
2316
-                                                     ),
2317
-                                'html_help_text'  => esc_html__(
2318
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2319
-                                    'event_espresso'
2320
-                                ),
2321
-                            )
2322
-                        ),
2323
-                    )
2324
-                ),
2325
-            )
2326
-        );
2327
-    }
2328
-
2329
-
2330
-    /**
2331
-     * _update_default_event_settings
2332
-     *
2333
-     * @access protected
2334
-     * @return void
2335
-     * @throws EE_Error
2336
-     */
2337
-    protected function _update_default_event_settings()
2338
-    {
2339
-        $registration_config = EE_Registry::instance()->CFG->registration;
2340
-        $form = $this->_default_event_settings_form();
2341
-        if ($form->was_submitted()) {
2342
-            $form->receive_form_submission();
2343
-            if ($form->is_valid()) {
2344
-                $valid_data = $form->valid_data();
2345
-                if (isset($valid_data['default_reg_status'])) {
2346
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2347
-                }
2348
-                if (isset($valid_data['default_max_tickets'])) {
2349
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2350
-                }
2351
-                // update because data was valid!
2352
-                EE_Registry::instance()->CFG->update_espresso_config();
2353
-                EE_Error::overwrite_success();
2354
-                EE_Error::add_success(
2355
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2356
-                );
2357
-            }
2358
-        }
2359
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2360
-    }
2361
-
2362
-
2363
-    /*************        Templates        *************/
2364
-    protected function _template_settings()
2365
-    {
2366
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2367
-        $this->_template_args['preview_img'] = '<img src="'
2368
-                                               . EVENTS_ASSETS_URL
2369
-                                               . '/images/'
2370
-                                               . 'caffeinated_template_features.jpg" alt="'
2371
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2372
-                                               . '" />';
2373
-        $this->_template_args['preview_text'] = '<strong>'
2374
-                                                . esc_html__(
2375
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2376
-                                                    'event_espresso'
2377
-                                                ) . '</strong>';
2378
-        $this->display_admin_caf_preview_page('template_settings_tab');
2379
-    }
2380
-
2381
-
2382
-    /** Event Category Stuff **/
2383
-    /**
2384
-     * set the _category property with the category object for the loaded page.
2385
-     *
2386
-     * @access private
2387
-     * @return void
2388
-     */
2389
-    private function _set_category_object()
2390
-    {
2391
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2392
-            return;
2393
-        } //already have the category object so get out.
2394
-        // set default category object
2395
-        $this->_set_empty_category_object();
2396
-        // only set if we've got an id
2397
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2398
-            return;
2399
-        }
2400
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2401
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2402
-        if (! empty($term)) {
2403
-            $this->_category->category_name = $term->name;
2404
-            $this->_category->category_identifier = $term->slug;
2405
-            $this->_category->category_desc = $term->description;
2406
-            $this->_category->id = $term->term_id;
2407
-            $this->_category->parent = $term->parent;
2408
-        }
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * Clears out category properties.
2414
-     */
2415
-    private function _set_empty_category_object()
2416
-    {
2417
-        $this->_category = new stdClass();
2418
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2419
-        $this->_category->id = $this->_category->parent = 0;
2420
-    }
2421
-
2422
-
2423
-    /**
2424
-     * @throws EE_Error
2425
-     */
2426
-    protected function _category_list_table()
2427
-    {
2428
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2429
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2430
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2431
-            'add_category',
2432
-            'add_category',
2433
-            array(),
2434
-            'add-new-h2'
2435
-        );
2436
-        $this->display_admin_list_table_page_with_sidebar();
2437
-    }
2438
-
2439
-
2440
-    /**
2441
-     * Output category details view.
2442
-     */
2443
-    protected function _category_details($view)
2444
-    {
2445
-        // load formatter helper
2446
-        // load field generator helper
2447
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2448
-        $this->_set_add_edit_form_tags($route);
2449
-        $this->_set_category_object();
2450
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2451
-        $delete_action = 'delete_category';
2452
-        // custom redirect
2453
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2454
-            array('action' => 'category_list'),
2455
-            $this->_admin_base_url
2456
-        );
2457
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2458
-        // take care of contents
2459
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2460
-        $this->display_admin_page_with_sidebar();
2461
-    }
2462
-
2463
-
2464
-    /**
2465
-     * Output category details content.
2466
-     */
2467
-    protected function _category_details_content()
2468
-    {
2469
-        $editor_args['category_desc'] = array(
2470
-            'type'          => 'wp_editor',
2471
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2472
-            'class'         => 'my_editor_custom',
2473
-            'wpeditor_args' => array('media_buttons' => false),
2474
-        );
2475
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2476
-        $all_terms = get_terms(
2477
-            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2478
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2479
-        );
2480
-        // setup category select for term parents.
2481
-        $category_select_values[] = array(
2482
-            'text' => esc_html__('No Parent', 'event_espresso'),
2483
-            'id'   => 0,
2484
-        );
2485
-        foreach ($all_terms as $term) {
2486
-            $category_select_values[] = array(
2487
-                'text' => $term->name,
2488
-                'id'   => $term->term_id,
2489
-            );
2490
-        }
2491
-        $category_select = EEH_Form_Fields::select_input(
2492
-            'category_parent',
2493
-            $category_select_values,
2494
-            $this->_category->parent
2495
-        );
2496
-        $template_args = array(
2497
-            'category'                 => $this->_category,
2498
-            'category_select'          => $category_select,
2499
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2500
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2501
-            'disable'                  => '',
2502
-            'disabled_message'         => false,
2503
-        );
2504
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2505
-        return EEH_Template::display_template($template, $template_args, true);
2506
-    }
2507
-
2508
-
2509
-    /**
2510
-     * Handles deleting categories.
2511
-     */
2512
-    protected function _delete_categories()
2513
-    {
2514
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2515
-            : (array) $this->_req_data['category_id'];
2516
-        foreach ($cat_ids as $cat_id) {
2517
-            $this->_delete_category($cat_id);
2518
-        }
2519
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2520
-        $query_args = array(
2521
-            'action' => 'category_list',
2522
-        );
2523
-        $this->_redirect_after_action(0, '', '', $query_args);
2524
-    }
2525
-
2526
-
2527
-    /**
2528
-     * Handles deleting specific category.
2529
-     *
2530
-     * @param int $cat_id
2531
-     */
2532
-    protected function _delete_category($cat_id)
2533
-    {
2534
-        $cat_id = absint($cat_id);
2535
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2536
-    }
2537
-
2538
-
2539
-    /**
2540
-     * Handles triggering the update or insertion of a new category.
2541
-     *
2542
-     * @param bool $new_category true means we're triggering the insert of a new category.
2543
-     */
2544
-    protected function _insert_or_update_category($new_category)
2545
-    {
2546
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2547
-        $success = 0; // we already have a success message so lets not send another.
2548
-        if ($cat_id) {
2549
-            $query_args = array(
2550
-                'action'     => 'edit_category',
2551
-                'EVT_CAT_ID' => $cat_id,
2552
-            );
2553
-        } else {
2554
-            $query_args = array('action' => 'add_category');
2555
-        }
2556
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2557
-    }
2558
-
2559
-
2560
-    /**
2561
-     * Inserts or updates category
2562
-     *
2563
-     * @param bool $update (true indicates we're updating a category).
2564
-     * @return bool|mixed|string
2565
-     */
2566
-    private function _insert_category($update = false)
2567
-    {
2568
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2569
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2570
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2571
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2572
-        if (empty($category_name)) {
2573
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2574
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2575
-            return false;
2576
-        }
2577
-        $term_args = array(
2578
-            'name'        => $category_name,
2579
-            'description' => $category_desc,
2580
-            'parent'      => $category_parent,
2581
-        );
2582
-        // was the category_identifier input disabled?
2583
-        if (isset($this->_req_data['category_identifier'])) {
2584
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2585
-        }
2586
-        $insert_ids = $update
2587
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2588
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2589
-        if (! is_array($insert_ids)) {
2590
-            $msg = esc_html__(
2591
-                'An error occurred and the category has not been saved to the database.',
2592
-                'event_espresso'
2593
-            );
2594
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2595
-        } else {
2596
-            $cat_id = $insert_ids['term_id'];
2597
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2598
-            EE_Error::add_success($msg);
2599
-        }
2600
-        return $cat_id;
2601
-    }
2602
-
2603
-
2604
-    /**
2605
-     * Gets categories or count of categories matching the arguments in the request.
2606
-     *
2607
-     * @param int  $per_page
2608
-     * @param int  $current_page
2609
-     * @param bool $count
2610
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2611
-     */
2612
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2613
-    {
2614
-        // testing term stuff
2615
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2616
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2617
-        $limit = ($current_page - 1) * $per_page;
2618
-        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2619
-        if (isset($this->_req_data['s'])) {
2620
-            $sstr = '%' . $this->_req_data['s'] . '%';
2621
-            $where['OR'] = array(
2622
-                'Term.name'   => array('LIKE', $sstr),
2623
-                'description' => array('LIKE', $sstr),
2624
-            );
2625
-        }
2626
-        $query_params = array(
2627
-            $where,
2628
-            'order_by'   => array($orderby => $order),
2629
-            'limit'      => $limit . ',' . $per_page,
2630
-            'force_join' => array('Term'),
2631
-        );
2632
-        $categories = $count
2633
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2634
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2635
-        return $categories;
2636
-    }
2637
-
2638
-    /* end category stuff */
2639
-    /**************/
2640
-
2641
-
2642
-    /**
2643
-     * Callback for the `ee_save_timezone_setting` ajax action.
2644
-     *
2645
-     * @throws EE_Error
2646
-     */
2647
-    public function save_timezonestring_setting()
2648
-    {
2649
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2650
-            ? $this->_req_data['timezone_selected']
2651
-            : '';
2652
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2653
-            EE_Error::add_error(
2654
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2655
-                __FILE__,
2656
-                __FUNCTION__,
2657
-                __LINE__
2658
-            );
2659
-            $this->_template_args['error'] = true;
2660
-            $this->_return_json();
2661
-        }
2662
-
2663
-        update_option('timezone_string', $timezone_string);
2664
-        EE_Error::add_success(
2665
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2666
-        );
2667
-        $this->_template_args['success'] = true;
2668
-        $this->_return_json(true, array('action' => 'create_new'));
2669
-    }
22
+	/**
23
+	 * This will hold the event object for event_details screen.
24
+	 *
25
+	 * @var EE_Event $_event
26
+	 */
27
+	protected $_event;
28
+
29
+
30
+	/**
31
+	 * This will hold the category object for category_details screen.
32
+	 *
33
+	 * @var stdClass $_category
34
+	 */
35
+	protected $_category;
36
+
37
+
38
+	/**
39
+	 * This will hold the event model instance
40
+	 *
41
+	 * @var EEM_Event $_event_model
42
+	 */
43
+	protected $_event_model;
44
+
45
+
46
+	/**
47
+	 * @var EE_Event
48
+	 */
49
+	protected $_cpt_model_obj = false;
50
+
51
+
52
+	/**
53
+	 * @var NodeGroupDao
54
+	 */
55
+	protected $model_obj_node_group_persister;
56
+
57
+	/**
58
+	 * Initialize page props for this admin page group.
59
+	 */
60
+	protected function _init_page_props()
61
+	{
62
+		$this->page_slug = EVENTS_PG_SLUG;
63
+		$this->page_label = EVENTS_LABEL;
64
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
65
+		$this->_admin_base_path = EVENTS_ADMIN;
66
+		$this->_cpt_model_names = array(
67
+			'create_new' => 'EEM_Event',
68
+			'edit'       => 'EEM_Event',
69
+		);
70
+		$this->_cpt_edit_routes = array(
71
+			'espresso_events' => 'edit',
72
+		);
73
+		add_action(
74
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
+			array($this, 'verify_event_edit'),
76
+			10,
77
+			2
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the ajax hooks used for this admin page group.
84
+	 */
85
+	protected function _ajax_hooks()
86
+	{
87
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
88
+	}
89
+
90
+
91
+	/**
92
+	 * Sets the page properties for this admin page group.
93
+	 */
94
+	protected function _define_page_props()
95
+	{
96
+		$this->_admin_page_title = EVENTS_LABEL;
97
+		$this->_labels = array(
98
+			'buttons'      => array(
99
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
100
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
+			),
106
+			'editor_title' => array(
107
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
+			),
109
+			'publishbox'   => array(
110
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
112
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	/**
121
+	 * Sets the page routes property for this admin page group.
122
+	 */
123
+	protected function _set_page_routes()
124
+	{
125
+		// load formatter helper
126
+		// load field generator helper
127
+		// is there a evt_id in the request?
128
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
+			? $this->_req_data['EVT_ID']
130
+			: 0;
131
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
+		$this->_page_routes = array(
133
+			'default'                       => array(
134
+				'func'       => '_events_overview_list_table',
135
+				'capability' => 'ee_read_events',
136
+			),
137
+			'create_new'                    => array(
138
+				'func'       => '_create_new_cpt_item',
139
+				'capability' => 'ee_edit_events',
140
+			),
141
+			'edit'                          => array(
142
+				'func'       => '_edit_cpt_item',
143
+				'capability' => 'ee_edit_event',
144
+				'obj_id'     => $evt_id,
145
+			),
146
+			'copy_event'                    => array(
147
+				'func'       => '_copy_events',
148
+				'capability' => 'ee_edit_event',
149
+				'obj_id'     => $evt_id,
150
+				'noheader'   => true,
151
+			),
152
+			'trash_event'                   => array(
153
+				'func'       => '_trash_or_restore_event',
154
+				'args'       => array('event_status' => 'trash'),
155
+				'capability' => 'ee_delete_event',
156
+				'obj_id'     => $evt_id,
157
+				'noheader'   => true,
158
+			),
159
+			'trash_events'                  => array(
160
+				'func'       => '_trash_or_restore_events',
161
+				'args'       => array('event_status' => 'trash'),
162
+				'capability' => 'ee_delete_events',
163
+				'noheader'   => true,
164
+			),
165
+			'restore_event'                 => array(
166
+				'func'       => '_trash_or_restore_event',
167
+				'args'       => array('event_status' => 'draft'),
168
+				'capability' => 'ee_delete_event',
169
+				'obj_id'     => $evt_id,
170
+				'noheader'   => true,
171
+			),
172
+			'restore_events'                => array(
173
+				'func'       => '_trash_or_restore_events',
174
+				'args'       => array('event_status' => 'draft'),
175
+				'capability' => 'ee_delete_events',
176
+				'noheader'   => true,
177
+			),
178
+			'delete_event'                  => array(
179
+				'func'       => '_delete_event',
180
+				'capability' => 'ee_delete_event',
181
+				'obj_id'     => $evt_id,
182
+				'noheader'   => true,
183
+			),
184
+			'delete_events'                 => array(
185
+				'func'       => '_delete_events',
186
+				'capability' => 'ee_delete_events',
187
+				'noheader'   => true,
188
+			),
189
+			'view_report'                   => array(
190
+				'func'      => '_view_report',
191
+				'capablity' => 'ee_edit_events',
192
+			),
193
+			'default_event_settings'        => array(
194
+				'func'       => '_default_event_settings',
195
+				'capability' => 'manage_options',
196
+			),
197
+			'update_default_event_settings' => array(
198
+				'func'       => '_update_default_event_settings',
199
+				'capability' => 'manage_options',
200
+				'noheader'   => true,
201
+			),
202
+			'template_settings'             => array(
203
+				'func'       => '_template_settings',
204
+				'capability' => 'manage_options',
205
+			),
206
+			// event category tab related
207
+			'add_category'                  => array(
208
+				'func'       => '_category_details',
209
+				'capability' => 'ee_edit_event_category',
210
+				'args'       => array('add'),
211
+			),
212
+			'edit_category'                 => array(
213
+				'func'       => '_category_details',
214
+				'capability' => 'ee_edit_event_category',
215
+				'args'       => array('edit'),
216
+			),
217
+			'delete_categories'             => array(
218
+				'func'       => '_delete_categories',
219
+				'capability' => 'ee_delete_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'delete_category'               => array(
223
+				'func'       => '_delete_categories',
224
+				'capability' => 'ee_delete_event_category',
225
+				'noheader'   => true,
226
+			),
227
+			'insert_category'               => array(
228
+				'func'       => '_insert_or_update_category',
229
+				'args'       => array('new_category' => true),
230
+				'capability' => 'ee_edit_event_category',
231
+				'noheader'   => true,
232
+			),
233
+			'update_category'               => array(
234
+				'func'       => '_insert_or_update_category',
235
+				'args'       => array('new_category' => false),
236
+				'capability' => 'ee_edit_event_category',
237
+				'noheader'   => true,
238
+			),
239
+			'category_list'                 => array(
240
+				'func'       => '_category_list_table',
241
+				'capability' => 'ee_manage_event_categories',
242
+			),
243
+			'preview_deletion' => [
244
+				'func' => 'previewDeletion',
245
+				'capability' => 'ee_delete_events',
246
+			],
247
+			'confirm_deletion' => [
248
+				'func' => 'confirmDeletion',
249
+				'capability' => 'ee_delete_events',
250
+				'noheader' => true,
251
+			]
252
+		);
253
+	}
254
+
255
+
256
+	/**
257
+	 * Set the _page_config property for this admin page group.
258
+	 */
259
+	protected function _set_page_config()
260
+	{
261
+		$this->_page_config = array(
262
+			'default'                => array(
263
+				'nav'           => array(
264
+					'label' => esc_html__('Overview', 'event_espresso'),
265
+					'order' => 10,
266
+				),
267
+				'list_table'    => 'Events_Admin_List_Table',
268
+				'help_tabs'     => array(
269
+					'events_overview_help_tab'                       => array(
270
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
271
+						'filename' => 'events_overview',
272
+					),
273
+					'events_overview_table_column_headings_help_tab' => array(
274
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
+						'filename' => 'events_overview_table_column_headings',
276
+					),
277
+					'events_overview_filters_help_tab'               => array(
278
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
+						'filename' => 'events_overview_filters',
280
+					),
281
+					'events_overview_view_help_tab'                  => array(
282
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
+						'filename' => 'events_overview_views',
284
+					),
285
+					'events_overview_other_help_tab'                 => array(
286
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
+						'filename' => 'events_overview_other',
288
+					),
289
+				),
290
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
+				// 'help_tour'     => array(
292
+				//     'Event_Overview_Help_Tour',
293
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
+				// ),
295
+				'qtips'         => array(
296
+					'EE_Event_List_Table_Tips',
297
+				),
298
+				'require_nonce' => false,
299
+			),
300
+			'create_new'             => array(
301
+				'nav'           => array(
302
+					'label'      => esc_html__('Add Event', 'event_espresso'),
303
+					'order'      => 5,
304
+					'persistent' => false,
305
+				),
306
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
307
+				'help_tabs'     => array(
308
+					'event_editor_help_tab'                            => array(
309
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
310
+						'filename' => 'event_editor',
311
+					),
312
+					'event_editor_title_richtexteditor_help_tab'       => array(
313
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
314
+						'filename' => 'event_editor_title_richtexteditor',
315
+					),
316
+					'event_editor_venue_details_help_tab'              => array(
317
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
318
+						'filename' => 'event_editor_venue_details',
319
+					),
320
+					'event_editor_event_datetimes_help_tab'            => array(
321
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
322
+						'filename' => 'event_editor_event_datetimes',
323
+					),
324
+					'event_editor_event_tickets_help_tab'              => array(
325
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
326
+						'filename' => 'event_editor_event_tickets',
327
+					),
328
+					'event_editor_event_registration_options_help_tab' => array(
329
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
330
+						'filename' => 'event_editor_event_registration_options',
331
+					),
332
+					'event_editor_tags_categories_help_tab'            => array(
333
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
334
+						'filename' => 'event_editor_tags_categories',
335
+					),
336
+					'event_editor_questions_registrants_help_tab'      => array(
337
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
338
+						'filename' => 'event_editor_questions_registrants',
339
+					),
340
+					'event_editor_save_new_event_help_tab'             => array(
341
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
342
+						'filename' => 'event_editor_save_new_event',
343
+					),
344
+					'event_editor_other_help_tab'                      => array(
345
+						'title'    => esc_html__('Event Other', 'event_espresso'),
346
+						'filename' => 'event_editor_other',
347
+					),
348
+				),
349
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
350
+				// 'help_tour'     => array(
351
+				//     'Event_Editor_Help_Tour',
352
+				// ),
353
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
354
+				'require_nonce' => false,
355
+			),
356
+			'edit'                   => array(
357
+				'nav'           => array(
358
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
359
+					'order'      => 5,
360
+					'persistent' => false,
361
+					'url'        => isset($this->_req_data['post'])
362
+						? EE_Admin_Page::add_query_args_and_nonce(
363
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
364
+							$this->_current_page_view_url
365
+						)
366
+						: $this->_admin_base_url,
367
+				),
368
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
369
+				'help_tabs'     => array(
370
+					'event_editor_help_tab'                            => array(
371
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
372
+						'filename' => 'event_editor',
373
+					),
374
+					'event_editor_title_richtexteditor_help_tab'       => array(
375
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
376
+						'filename' => 'event_editor_title_richtexteditor',
377
+					),
378
+					'event_editor_venue_details_help_tab'              => array(
379
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
380
+						'filename' => 'event_editor_venue_details',
381
+					),
382
+					'event_editor_event_datetimes_help_tab'            => array(
383
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
384
+						'filename' => 'event_editor_event_datetimes',
385
+					),
386
+					'event_editor_event_tickets_help_tab'              => array(
387
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
388
+						'filename' => 'event_editor_event_tickets',
389
+					),
390
+					'event_editor_event_registration_options_help_tab' => array(
391
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
392
+						'filename' => 'event_editor_event_registration_options',
393
+					),
394
+					'event_editor_tags_categories_help_tab'            => array(
395
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
396
+						'filename' => 'event_editor_tags_categories',
397
+					),
398
+					'event_editor_questions_registrants_help_tab'      => array(
399
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
400
+						'filename' => 'event_editor_questions_registrants',
401
+					),
402
+					'event_editor_save_new_event_help_tab'             => array(
403
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
404
+						'filename' => 'event_editor_save_new_event',
405
+					),
406
+					'event_editor_other_help_tab'                      => array(
407
+						'title'    => esc_html__('Event Other', 'event_espresso'),
408
+						'filename' => 'event_editor_other',
409
+					),
410
+				),
411
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
412
+				'require_nonce' => false,
413
+			),
414
+			'default_event_settings' => array(
415
+				'nav'           => array(
416
+					'label' => esc_html__('Default Settings', 'event_espresso'),
417
+					'order' => 40,
418
+				),
419
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
420
+				'labels'        => array(
421
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
422
+				),
423
+				'help_tabs'     => array(
424
+					'default_settings_help_tab'        => array(
425
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
426
+						'filename' => 'events_default_settings',
427
+					),
428
+					'default_settings_status_help_tab' => array(
429
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
430
+						'filename' => 'events_default_settings_status',
431
+					),
432
+					'default_maximum_tickets_help_tab' => array(
433
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
434
+						'filename' => 'events_default_settings_max_tickets',
435
+					),
436
+				),
437
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
438
+				// 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
439
+				'require_nonce' => false,
440
+			),
441
+			// template settings
442
+			'template_settings'      => array(
443
+				'nav'           => array(
444
+					'label' => esc_html__('Templates', 'event_espresso'),
445
+					'order' => 30,
446
+				),
447
+				'metaboxes'     => $this->_default_espresso_metaboxes,
448
+				'help_tabs'     => array(
449
+					'general_settings_templates_help_tab' => array(
450
+						'title'    => esc_html__('Templates', 'event_espresso'),
451
+						'filename' => 'general_settings_templates',
452
+					),
453
+				),
454
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
455
+				// 'help_tour'     => array('Templates_Help_Tour'),
456
+				'require_nonce' => false,
457
+			),
458
+			// event category stuff
459
+			'add_category'           => array(
460
+				'nav'           => array(
461
+					'label'      => esc_html__('Add Category', 'event_espresso'),
462
+					'order'      => 15,
463
+					'persistent' => false,
464
+				),
465
+				'help_tabs'     => array(
466
+					'add_category_help_tab' => array(
467
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
468
+						'filename' => 'events_add_category',
469
+					),
470
+				),
471
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
472
+				// 'help_tour'     => array('Event_Add_Category_Help_Tour'),
473
+				'metaboxes'     => array('_publish_post_box'),
474
+				'require_nonce' => false,
475
+			),
476
+			'edit_category'          => array(
477
+				'nav'           => array(
478
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
479
+					'order'      => 15,
480
+					'persistent' => false,
481
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
482
+						? add_query_arg(
483
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
484
+							$this->_current_page_view_url
485
+						)
486
+						: $this->_admin_base_url,
487
+				),
488
+				'help_tabs'     => array(
489
+					'edit_category_help_tab' => array(
490
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
491
+						'filename' => 'events_edit_category',
492
+					),
493
+				),
494
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
495
+				'metaboxes'     => array('_publish_post_box'),
496
+				'require_nonce' => false,
497
+			),
498
+			'category_list'          => array(
499
+				'nav'           => array(
500
+					'label' => esc_html__('Categories', 'event_espresso'),
501
+					'order' => 20,
502
+				),
503
+				'list_table'    => 'Event_Categories_Admin_List_Table',
504
+				'help_tabs'     => array(
505
+					'events_categories_help_tab'                       => array(
506
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
507
+						'filename' => 'events_categories',
508
+					),
509
+					'events_categories_table_column_headings_help_tab' => array(
510
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
511
+						'filename' => 'events_categories_table_column_headings',
512
+					),
513
+					'events_categories_view_help_tab'                  => array(
514
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
515
+						'filename' => 'events_categories_views',
516
+					),
517
+					'events_categories_other_help_tab'                 => array(
518
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
519
+						'filename' => 'events_categories_other',
520
+					),
521
+				),
522
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
523
+				// 'help_tour'     => array(
524
+				//     'Event_Categories_Help_Tour',
525
+				// ),
526
+				'metaboxes'     => $this->_default_espresso_metaboxes,
527
+				'require_nonce' => false,
528
+			),
529
+			'preview_deletion'           => array(
530
+				'nav'           => array(
531
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
532
+					'order'      => 15,
533
+					'persistent' => false,
534
+					'url'        => '',
535
+				),
536
+				'require_nonce' => false
537
+			)
538
+		);
539
+	}
540
+
541
+
542
+	/**
543
+	 * Used to register any global screen options if necessary for every route in this admin page group.
544
+	 */
545
+	protected function _add_screen_options()
546
+	{
547
+	}
548
+
549
+
550
+	/**
551
+	 * Implementing the screen options for the 'default' route.
552
+	 */
553
+	protected function _add_screen_options_default()
554
+	{
555
+		$this->_per_page_screen_option();
556
+	}
557
+
558
+
559
+	/**
560
+	 * Implementing screen options for the category list route.
561
+	 */
562
+	protected function _add_screen_options_category_list()
563
+	{
564
+		$page_title = $this->_admin_page_title;
565
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
566
+		$this->_per_page_screen_option();
567
+		$this->_admin_page_title = $page_title;
568
+	}
569
+
570
+
571
+	/**
572
+	 * Used to register any global feature pointers for the admin page group.
573
+	 */
574
+	protected function _add_feature_pointers()
575
+	{
576
+	}
577
+
578
+
579
+	/**
580
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
581
+	 */
582
+	public function load_scripts_styles()
583
+	{
584
+		wp_register_style(
585
+			'events-admin-css',
586
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
587
+			array(),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591
+		wp_enqueue_style('events-admin-css');
592
+		wp_enqueue_style('ee-cat-admin');
593
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
594
+		// registers for all views
595
+		// scripts
596
+		wp_register_script(
597
+			'event_editor_js',
598
+			EVENTS_ASSETS_URL . 'event_editor.js',
599
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
600
+			EVENT_ESPRESSO_VERSION,
601
+			true
602
+		);
603
+	}
604
+
605
+
606
+	/**
607
+	 * Enqueuing scripts and styles specific to this view
608
+	 */
609
+	public function load_scripts_styles_create_new()
610
+	{
611
+		$this->load_scripts_styles_edit();
612
+	}
613
+
614
+
615
+	/**
616
+	 * Enqueuing scripts and styles specific to this view
617
+	 */
618
+	public function load_scripts_styles_edit()
619
+	{
620
+		// styles
621
+		wp_enqueue_style('espresso-ui-theme');
622
+		wp_register_style(
623
+			'event-editor-css',
624
+			EVENTS_ASSETS_URL . 'event-editor.css',
625
+			array('ee-admin-css'),
626
+			EVENT_ESPRESSO_VERSION
627
+		);
628
+		wp_enqueue_style('event-editor-css');
629
+		// scripts
630
+		wp_register_script(
631
+			'event-datetime-metabox',
632
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
633
+			array('event_editor_js', 'ee-datepicker'),
634
+			EVENT_ESPRESSO_VERSION
635
+		);
636
+		wp_enqueue_script('event-datetime-metabox');
637
+	}
638
+
639
+
640
+	/**
641
+	 * Populating the _views property for the category list table view.
642
+	 */
643
+	protected function _set_list_table_views_category_list()
644
+	{
645
+		$this->_views = array(
646
+			'all' => array(
647
+				'slug'        => 'all',
648
+				'label'       => esc_html__('All', 'event_espresso'),
649
+				'count'       => 0,
650
+				'bulk_action' => array(
651
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
652
+				),
653
+			),
654
+		);
655
+	}
656
+
657
+
658
+	/**
659
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
660
+	 */
661
+	public function admin_init()
662
+	{
663
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
664
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
665
+			'event_espresso'
666
+		);
667
+	}
668
+
669
+
670
+	/**
671
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
672
+	 * group.
673
+	 */
674
+	public function admin_notices()
675
+	{
676
+	}
677
+
678
+
679
+	/**
680
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
681
+	 * this admin page group.
682
+	 */
683
+	public function admin_footer_scripts()
684
+	{
685
+	}
686
+
687
+
688
+	/**
689
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
690
+	 * warning (via EE_Error::add_error());
691
+	 *
692
+	 * @param  EE_Event $event Event object
693
+	 * @param string    $req_type
694
+	 * @return void
695
+	 * @throws EE_Error
696
+	 * @access public
697
+	 */
698
+	public function verify_event_edit($event = null, $req_type = '')
699
+	{
700
+		// don't need to do this when processing
701
+		if (! empty($req_type)) {
702
+			return;
703
+		}
704
+		// no event?
705
+		if (empty($event)) {
706
+			// set event
707
+			$event = $this->_cpt_model_obj;
708
+		}
709
+		// STILL no event?
710
+		if (! $event instanceof EE_Event) {
711
+			return;
712
+		}
713
+		$orig_status = $event->status();
714
+		// first check if event is active.
715
+		if (
716
+			$orig_status === EEM_Event::cancelled
717
+			|| $orig_status === EEM_Event::postponed
718
+			|| $event->is_expired()
719
+			|| $event->is_inactive()
720
+		) {
721
+			return;
722
+		}
723
+		// made it here so it IS active... next check that any of the tickets are sold.
724
+		if ($event->is_sold_out(true)) {
725
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
+				EE_Error::add_attention(
727
+					sprintf(
728
+						esc_html__(
729
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
730
+							'event_espresso'
731
+						),
732
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
+					)
734
+				);
735
+			}
736
+			return;
737
+		} elseif ($orig_status === EEM_Event::sold_out) {
738
+			EE_Error::add_attention(
739
+				sprintf(
740
+					esc_html__(
741
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
742
+						'event_espresso'
743
+					),
744
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
745
+				)
746
+			);
747
+		}
748
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
+		if (! $event->tickets_on_sale()) {
750
+			return;
751
+		}
752
+		// made it here so show warning
753
+		$this->_edit_event_warning();
754
+	}
755
+
756
+
757
+	/**
758
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
759
+	 * When needed, hook this into a EE_Error::add_error() notice.
760
+	 *
761
+	 * @access protected
762
+	 * @return void
763
+	 */
764
+	protected function _edit_event_warning()
765
+	{
766
+		// we don't want to add warnings during these requests
767
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
+			return;
769
+		}
770
+		EE_Error::add_attention(
771
+			sprintf(
772
+				esc_html__(
773
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
+					'event_espresso'
775
+				),
776
+				'<a class="espresso-help-tab-lnk">',
777
+				'</a>'
778
+			)
779
+		);
780
+	}
781
+
782
+
783
+	/**
784
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
785
+	 * Otherwise, do the normal logic
786
+	 *
787
+	 * @return string
788
+	 * @throws \EE_Error
789
+	 */
790
+	protected function _create_new_cpt_item()
791
+	{
792
+		$has_timezone_string = get_option('timezone_string');
793
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
794
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
+			EE_Error::add_attention(
796
+				sprintf(
797
+					esc_html__(
798
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
799
+						'event_espresso'
800
+					),
801
+					'<br>',
802
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
+					. '</select>',
805
+					'<button class="button button-secondary timezone-submit">',
806
+					'</button><span class="spinner"></span>'
807
+				),
808
+				__FILE__,
809
+				__FUNCTION__,
810
+				__LINE__
811
+			);
812
+		}
813
+		return parent::_create_new_cpt_item();
814
+	}
815
+
816
+
817
+	/**
818
+	 * Sets the _views property for the default route in this admin page group.
819
+	 */
820
+	protected function _set_list_table_views_default()
821
+	{
822
+		$this->_views = array(
823
+			'all'   => array(
824
+				'slug'        => 'all',
825
+				'label'       => esc_html__('View All Events', 'event_espresso'),
826
+				'count'       => 0,
827
+				'bulk_action' => array(
828
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
+				),
830
+			),
831
+			'draft' => array(
832
+				'slug'        => 'draft',
833
+				'label'       => esc_html__('Draft', 'event_espresso'),
834
+				'count'       => 0,
835
+				'bulk_action' => array(
836
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
+				),
838
+			),
839
+		);
840
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
+			$this->_views['trash'] = array(
842
+				'slug'        => 'trash',
843
+				'label'       => esc_html__('Trash', 'event_espresso'),
844
+				'count'       => 0,
845
+				'bulk_action' => array(
846
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
+				),
849
+			);
850
+		}
851
+	}
852
+
853
+
854
+	/**
855
+	 * Provides the legend item array for the default list table view.
856
+	 *
857
+	 * @return array
858
+	 */
859
+	protected function _event_legend_items()
860
+	{
861
+		$items = array(
862
+			'view_details'   => array(
863
+				'class' => 'dashicons dashicons-search',
864
+				'desc'  => esc_html__('View Event', 'event_espresso'),
865
+			),
866
+			'edit_event'     => array(
867
+				'class' => 'ee-icon ee-icon-calendar-edit',
868
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
+			),
870
+			'view_attendees' => array(
871
+				'class' => 'dashicons dashicons-groups',
872
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
+			),
874
+		);
875
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
+		$statuses = array(
877
+			'sold_out_status'  => array(
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
+			),
881
+			'active_status'    => array(
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
+			),
885
+			'upcoming_status'  => array(
886
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
+			),
889
+			'postponed_status' => array(
890
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
+			),
893
+			'cancelled_status' => array(
894
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
+			),
897
+			'expired_status'   => array(
898
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
+			),
901
+			'inactive_status'  => array(
902
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
+			),
905
+		);
906
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
+		return array_merge($items, $statuses);
908
+	}
909
+
910
+
911
+	/**
912
+	 * @return EEM_Event
913
+	 */
914
+	private function _event_model()
915
+	{
916
+		if (! $this->_event_model instanceof EEM_Event) {
917
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
918
+		}
919
+		return $this->_event_model;
920
+	}
921
+
922
+
923
+	/**
924
+	 * Adds extra buttons to the WP CPT permalink field row.
925
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
+	 *
927
+	 * @param  string $return    the current html
928
+	 * @param  int    $id        the post id for the page
929
+	 * @param  string $new_title What the title is
930
+	 * @param  string $new_slug  what the slug is
931
+	 * @return string            The new html string for the permalink area
932
+	 */
933
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
+	{
935
+		// make sure this is only when editing
936
+		if (! empty($id)) {
937
+			$post = get_post($id);
938
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
+					   . esc_html__('Shortcode', 'event_espresso')
940
+					   . '</a> ';
941
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
+					   . $post->ID
943
+					   . ']">';
944
+		}
945
+		return $return;
946
+	}
947
+
948
+
949
+	/**
950
+	 * _events_overview_list_table
951
+	 * This contains the logic for showing the events_overview list
952
+	 *
953
+	 * @access protected
954
+	 * @return void
955
+	 * @throws \EE_Error
956
+	 */
957
+	protected function _events_overview_list_table()
958
+	{
959
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
+			? (array) $this->_template_args['after_list_table']
962
+			: array();
963
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
+				. EEH_Template::get_button_or_link(
965
+					get_post_type_archive_link('espresso_events'),
966
+					esc_html__("View Event Archive Page", "event_espresso"),
967
+					'button'
968
+				);
969
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
+			'create_new',
972
+			'add',
973
+			array(),
974
+			'add-new-h2'
975
+		);
976
+		$this->display_admin_list_table_page_with_no_sidebar();
977
+	}
978
+
979
+
980
+	/**
981
+	 * this allows for extra misc actions in the default WP publish box
982
+	 *
983
+	 * @return void
984
+	 */
985
+	public function extra_misc_actions_publish_box()
986
+	{
987
+		$this->_generate_publish_box_extra_content();
988
+	}
989
+
990
+
991
+	/**
992
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
+	 * saved.
994
+	 * Typically you would use this to save any additional data.
995
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
+	 * ALSO very important.  When a post transitions from scheduled to published,
997
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
+	 * other meta saves. So MAKE sure that you handle this accordingly.
999
+	 *
1000
+	 * @access protected
1001
+	 * @abstract
1002
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
+	 * @param  object $post    The post object of the cpt that was saved.
1004
+	 * @return void
1005
+	 * @throws \EE_Error
1006
+	 */
1007
+	protected function _insert_update_cpt_item($post_id, $post)
1008
+	{
1009
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
+			// get out we're not processing an event save.
1011
+			return;
1012
+		}
1013
+		$event_values = array(
1014
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
+			'EVT_additional_limit'            => min(
1017
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
+			),
1020
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
+				? $this->_req_data['EVT_default_registration_status']
1022
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
+				? $this->_req_data['timezone_string'] : null,
1027
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
+				? $this->_req_data['externalURL'] : null,
1029
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
+				? $this->_req_data['event_phone'] : null,
1031
+		);
1032
+		// update event
1033
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
+		// get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1035
+		$get_one_where = array(
1036
+			$this->_event_model()->primary_key_name() => $post_id,
1037
+			'OR'                                      => array(
1038
+				'status'   => $post->post_status,
1039
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
+				// but the returned object here has a status of "publish", so use the original post status as well
1041
+				'status*1' => $this->_req_data['original_post_status'],
1042
+			),
1043
+		);
1044
+		$event = $this->_event_model()->get_one(array($get_one_where));
1045
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
+		$event_update_callbacks = apply_filters(
1047
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
+			array(
1049
+				array($this, '_default_venue_update'),
1050
+				array($this, '_default_tickets_update'),
1051
+			)
1052
+		);
1053
+		$att_success = true;
1054
+		foreach ($event_update_callbacks as $e_callback) {
1055
+			$_success = is_callable($e_callback)
1056
+				? call_user_func($e_callback, $event, $this->_req_data)
1057
+				: false;
1058
+			// if ANY of these updates fail then we want the appropriate global error message
1059
+			$att_success = ! $att_success ? $att_success : $_success;
1060
+		}
1061
+		// any errors?
1062
+		if ($success && false === $att_success) {
1063
+			EE_Error::add_error(
1064
+				esc_html__(
1065
+					'Event Details saved successfully but something went wrong with saving attachments.',
1066
+					'event_espresso'
1067
+				),
1068
+				__FILE__,
1069
+				__FUNCTION__,
1070
+				__LINE__
1071
+			);
1072
+		} elseif ($success === false) {
1073
+			EE_Error::add_error(
1074
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
+				__FILE__,
1076
+				__FUNCTION__,
1077
+				__LINE__
1078
+			);
1079
+		}
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * @see parent::restore_item()
1085
+	 * @param int $post_id
1086
+	 * @param int $revision_id
1087
+	 */
1088
+	protected function _restore_cpt_item($post_id, $revision_id)
1089
+	{
1090
+		// copy existing event meta to new post
1091
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
+		if ($post_evt instanceof EE_Event) {
1093
+			// meta revision restore
1094
+			$post_evt->restore_revision($revision_id);
1095
+			// related objs restore
1096
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
+		}
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Attach the venue to the Event
1103
+	 *
1104
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1105
+	 * @param  array     $data   The request data from the form
1106
+	 * @return bool           Success or fail.
1107
+	 */
1108
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
+	{
1110
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1112
+		$rows_affected = null;
1113
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
+		// very important.  If we don't have a venue name...
1115
+		// then we'll get out because not necessary to create empty venue
1116
+		if (empty($data['venue_title'])) {
1117
+			return false;
1118
+		}
1119
+		$venue_array = array(
1120
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
+				: null,
1126
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
+			'status'              => 'publish',
1139
+		);
1140
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
+		if (! empty($venue_id)) {
1142
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1143
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1144
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1145
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1146
+			return $rows_affected > 0 ? true : false;
1147
+		} else {
1148
+			// we insert the venue
1149
+			$venue_id = $venue_model->insert($venue_array);
1150
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1151
+			return ! empty($venue_id) ? true : false;
1152
+		}
1153
+		// when we have the ancestor come in it's already been handled by the revision save.
1154
+	}
1155
+
1156
+
1157
+	/**
1158
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
+	 *
1160
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1161
+	 * @param  array    $data   The request data from the form
1162
+	 * @return array
1163
+	 */
1164
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
+	{
1166
+		$success = true;
1167
+		$saved_dtt = null;
1168
+		$saved_tickets = array();
1169
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1170
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
+			// trim all values to ensure any excess whitespace is removed.
1172
+			$dtt = array_map('trim', $dtt);
1173
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
+				: $dtt['DTT_EVT_start'];
1175
+			$datetime_values = array(
1176
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
+				'DTT_order'     => $row,
1181
+			);
1182
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
+			if (! empty($dtt['DTT_ID'])) {
1184
+				$DTM = EE_Registry::instance()
1185
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
+								  ->get_one_by_ID($dtt['DTT_ID']);
1187
+				$DTM->set_date_format($incoming_date_formats[0]);
1188
+				$DTM->set_time_format($incoming_date_formats[1]);
1189
+				foreach ($datetime_values as $field => $value) {
1190
+					$DTM->set($field, $value);
1191
+				}
1192
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1194
+			} else {
1195
+				$DTM = EE_Registry::instance()->load_class(
1196
+					'Datetime',
1197
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
+					false,
1199
+					false
1200
+				);
1201
+				foreach ($datetime_values as $field => $value) {
1202
+					$DTM->set($field, $value);
1203
+				}
1204
+			}
1205
+			$DTM->save();
1206
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
+			// load DTT helper
1208
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
+				$DTT->save();
1213
+			}
1214
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
+			$saved_dtt = $DTT;
1216
+			$success = ! $success ? $success : $DTT;
1217
+			// if ANY of these updates fail then we want the appropriate global error message.
1218
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1219
+		}
1220
+		// no dtts get deleted so we don't do any of that logic here.
1221
+		// update tickets next
1222
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1224
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1225
+			$update_prices = false;
1226
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
+			// trim inputs to ensure any excess whitespace is removed.
1229
+			$tkt = array_map('trim', $tkt);
1230
+			if (empty($tkt['TKT_start_date'])) {
1231
+				// let's use now in the set timezone.
1232
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
+			}
1235
+			if (empty($tkt['TKT_end_date'])) {
1236
+				// use the start date of the first datetime
1237
+				$dtt = $evtobj->first_datetime();
1238
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
+					$incoming_date_formats[0],
1240
+					$incoming_date_formats[1]
1241
+				);
1242
+			}
1243
+			$TKT_values = array(
1244
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1249
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1250
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
+				'TKT_row'         => $row,
1255
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
+				'TKT_price'       => $ticket_price,
1257
+			);
1258
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
+				$TKT_values['TKT_ID'] = 0;
1261
+				$TKT_values['TKT_is_default'] = 0;
1262
+				$TKT_values['TKT_price'] = $ticket_price;
1263
+				$update_prices = true;
1264
+			}
1265
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
+			if (! empty($tkt['TKT_ID'])) {
1269
+				$TKT = EE_Registry::instance()
1270
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
+								  ->get_one_by_ID($tkt['TKT_ID']);
1272
+				if ($TKT instanceof EE_Ticket) {
1273
+					$ticket_sold = $TKT->count_related(
1274
+						'Registration',
1275
+						array(
1276
+							array(
1277
+								'STS_ID' => array(
1278
+									'NOT IN',
1279
+									array(EEM_Registration::status_id_incomplete),
1280
+								),
1281
+							),
1282
+						)
1283
+					) > 0 ? true : false;
1284
+					// let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
+									  && ! $TKT->get('TKT_deleted');
1287
+					$TKT->set_date_format($incoming_date_formats[0]);
1288
+					$TKT->set_time_format($incoming_date_formats[1]);
1289
+					// set new values
1290
+					foreach ($TKT_values as $field => $value) {
1291
+						if ($field == 'TKT_qty') {
1292
+							$TKT->set_qty($value);
1293
+						} else {
1294
+							$TKT->set($field, $value);
1295
+						}
1296
+					}
1297
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
+					if ($create_new_TKT) {
1299
+						// archive the old ticket first
1300
+						$TKT->set('TKT_deleted', 1);
1301
+						$TKT->save();
1302
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1304
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
+						$TKT = clone $TKT;
1306
+						$TKT->set('TKT_ID', 0);
1307
+						$TKT->set('TKT_deleted', 0);
1308
+						$TKT->set('TKT_price', $ticket_price);
1309
+						$TKT->set('TKT_sold', 0);
1310
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1311
+						$update_prices = true;
1312
+					}
1313
+					// make sure price is set if it hasn't been already
1314
+					$TKT->set('TKT_price', $ticket_price);
1315
+				}
1316
+			} else {
1317
+				// no TKT_id so a new TKT
1318
+				$TKT_values['TKT_price'] = $ticket_price;
1319
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
+				if ($TKT instanceof EE_Ticket) {
1321
+					// need to reset values to properly account for the date formats
1322
+					$TKT->set_date_format($incoming_date_formats[0]);
1323
+					$TKT->set_time_format($incoming_date_formats[1]);
1324
+					$TKT->set_timezone($evtobj->get_timezone());
1325
+					// set new values
1326
+					foreach ($TKT_values as $field => $value) {
1327
+						if ($field == 'TKT_qty') {
1328
+							$TKT->set_qty($value);
1329
+						} else {
1330
+							$TKT->set($field, $value);
1331
+						}
1332
+					}
1333
+					$update_prices = true;
1334
+				}
1335
+			}
1336
+			// cap ticket qty by datetime reg limits
1337
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
+			// update ticket.
1339
+			$TKT->save();
1340
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
+				$TKT->save();
1345
+			}
1346
+			// initially let's add the ticket to the dtt
1347
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1349
+			// add prices to ticket
1350
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
+		}
1352
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
+		foreach ($tickets_removed as $id) {
1356
+			$id = absint($id);
1357
+			// get the ticket for this id
1358
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
+			if ( ! $tkt_to_remove instanceof EE_Ticket) {
1360
+				continue;
1361
+			}
1362
+
1363
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1364
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1365
+			foreach ($dtts as $dtt) {
1366
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1367
+			}
1368
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1369
+			$tkt_to_remove->delete_related_permanently('Price');
1370
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1371
+			$tkt_to_remove->delete_permanently();
1372
+		}
1373
+		return array($saved_dtt, $saved_tickets);
1374
+	}
1375
+
1376
+
1377
+	/**
1378
+	 * This attaches a list of given prices to a ticket.
1379
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1380
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1381
+	 * price info and prices are automatically "archived" via the ticket.
1382
+	 *
1383
+	 * @access  private
1384
+	 * @param array     $prices     Array of prices from the form.
1385
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1386
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1387
+	 * @return  void
1388
+	 */
1389
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1390
+	{
1391
+		foreach ($prices as $row => $prc) {
1392
+			$PRC_values = array(
1393
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1394
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1395
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1396
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1397
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1398
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1399
+				'PRC_order'      => $row,
1400
+			);
1401
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1402
+				$PRC_values['PRC_ID'] = 0;
1403
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1404
+			} else {
1405
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1406
+				// update this price with new values
1407
+				foreach ($PRC_values as $field => $newprc) {
1408
+					$PRC->set($field, $newprc);
1409
+				}
1410
+				$PRC->save();
1411
+			}
1412
+			$ticket->_add_relation_to($PRC, 'Price');
1413
+		}
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * Add in our autosave ajax handlers
1419
+	 *
1420
+	 */
1421
+	protected function _ee_autosave_create_new()
1422
+	{
1423
+	}
1424
+
1425
+
1426
+	/**
1427
+	 * More autosave handlers.
1428
+	 */
1429
+	protected function _ee_autosave_edit()
1430
+	{
1431
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1432
+	}
1433
+
1434
+
1435
+	/**
1436
+	 *    _generate_publish_box_extra_content
1437
+	 */
1438
+	private function _generate_publish_box_extra_content()
1439
+	{
1440
+		// load formatter helper
1441
+		// args for getting related registrations
1442
+		$approved_query_args = array(
1443
+			array(
1444
+				'REG_deleted' => 0,
1445
+				'STS_ID'      => EEM_Registration::status_id_approved,
1446
+			),
1447
+		);
1448
+		$not_approved_query_args = array(
1449
+			array(
1450
+				'REG_deleted' => 0,
1451
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1452
+			),
1453
+		);
1454
+		$pending_payment_query_args = array(
1455
+			array(
1456
+				'REG_deleted' => 0,
1457
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1458
+			),
1459
+		);
1460
+		// publish box
1461
+		$publish_box_extra_args = array(
1462
+			'view_approved_reg_url'        => add_query_arg(
1463
+				array(
1464
+					'action'      => 'default',
1465
+					'event_id'    => $this->_cpt_model_obj->ID(),
1466
+					'_reg_status' => EEM_Registration::status_id_approved,
1467
+				),
1468
+				REG_ADMIN_URL
1469
+			),
1470
+			'view_not_approved_reg_url'    => add_query_arg(
1471
+				array(
1472
+					'action'      => 'default',
1473
+					'event_id'    => $this->_cpt_model_obj->ID(),
1474
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1475
+				),
1476
+				REG_ADMIN_URL
1477
+			),
1478
+			'view_pending_payment_reg_url' => add_query_arg(
1479
+				array(
1480
+					'action'      => 'default',
1481
+					'event_id'    => $this->_cpt_model_obj->ID(),
1482
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1483
+				),
1484
+				REG_ADMIN_URL
1485
+			),
1486
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1487
+				'Registration',
1488
+				$approved_query_args
1489
+			),
1490
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1491
+				'Registration',
1492
+				$not_approved_query_args
1493
+			),
1494
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1495
+				'Registration',
1496
+				$pending_payment_query_args
1497
+			),
1498
+			'misc_pub_section_class'       => apply_filters(
1499
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1500
+				'misc-pub-section'
1501
+			),
1502
+		);
1503
+		ob_start();
1504
+		do_action(
1505
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1506
+			$this->_cpt_model_obj
1507
+		);
1508
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1509
+		// load template
1510
+		EEH_Template::display_template(
1511
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1512
+			$publish_box_extra_args
1513
+		);
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * @return EE_Event
1519
+	 */
1520
+	public function get_event_object()
1521
+	{
1522
+		return $this->_cpt_model_obj;
1523
+	}
1524
+
1525
+
1526
+
1527
+
1528
+	/** METABOXES * */
1529
+	/**
1530
+	 * _register_event_editor_meta_boxes
1531
+	 * add all metaboxes related to the event_editor
1532
+	 *
1533
+	 * @return void
1534
+	 */
1535
+	protected function _register_event_editor_meta_boxes()
1536
+	{
1537
+		$this->verify_cpt_object();
1538
+		add_meta_box(
1539
+			'espresso_event_editor_tickets',
1540
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1541
+			array($this, 'ticket_metabox'),
1542
+			$this->page_slug,
1543
+			'normal',
1544
+			'high'
1545
+		);
1546
+		add_meta_box(
1547
+			'espresso_event_editor_event_options',
1548
+			esc_html__('Event Registration Options', 'event_espresso'),
1549
+			array($this, 'registration_options_meta_box'),
1550
+			$this->page_slug,
1551
+			'side',
1552
+			'default'
1553
+		);
1554
+		// NOTE: if you're looking for other metaboxes in here,
1555
+		// where a metabox has a related management page in the admin
1556
+		// you will find it setup in the related management page's "_Hooks" file.
1557
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1558
+	}
1559
+
1560
+
1561
+	/**
1562
+	 * @throws DomainException
1563
+	 * @throws EE_Error
1564
+	 */
1565
+	public function ticket_metabox()
1566
+	{
1567
+		$existing_datetime_ids = $existing_ticket_ids = array();
1568
+		// defaults for template args
1569
+		$template_args = array(
1570
+			'existing_datetime_ids'    => '',
1571
+			'event_datetime_help_link' => '',
1572
+			'ticket_options_help_link' => '',
1573
+			'time'                     => null,
1574
+			'ticket_rows'              => '',
1575
+			'existing_ticket_ids'      => '',
1576
+			'total_ticket_rows'        => 1,
1577
+			'ticket_js_structure'      => '',
1578
+			'trash_icon'               => 'ee-lock-icon',
1579
+			'disabled'                 => '',
1580
+		);
1581
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1582
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1583
+		/**
1584
+		 * 1. Start with retrieving Datetimes
1585
+		 * 2. Fore each datetime get related tickets
1586
+		 * 3. For each ticket get related prices
1587
+		 */
1588
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1589
+		/** @type EE_Datetime $first_datetime */
1590
+		$first_datetime = reset($times);
1591
+		// do we get related tickets?
1592
+		if (
1593
+			$first_datetime instanceof EE_Datetime
1594
+			&& $first_datetime->ID() !== 0
1595
+		) {
1596
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1597
+			$template_args['time'] = $first_datetime;
1598
+			$related_tickets = $first_datetime->tickets(
1599
+				array(
1600
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1601
+					'default_where_conditions' => 'none',
1602
+				)
1603
+			);
1604
+			if (! empty($related_tickets)) {
1605
+				$template_args['total_ticket_rows'] = count($related_tickets);
1606
+				$row = 0;
1607
+				foreach ($related_tickets as $ticket) {
1608
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1609
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1610
+					$row++;
1611
+				}
1612
+			} else {
1613
+				$template_args['total_ticket_rows'] = 1;
1614
+				/** @type EE_Ticket $ticket */
1615
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1616
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1617
+			}
1618
+		} else {
1619
+			$template_args['time'] = $times[0];
1620
+			/** @type EE_Ticket $ticket */
1621
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1622
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1623
+			// NOTE: we're just sending the first default row
1624
+			// (decaf can't manage default tickets so this should be sufficient);
1625
+		}
1626
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1627
+			'event_editor_event_datetimes_help_tab'
1628
+		);
1629
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1630
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1631
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1632
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1633
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1634
+			true
1635
+		);
1636
+		$template = apply_filters(
1637
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1638
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1639
+		);
1640
+		EEH_Template::display_template($template, $template_args);
1641
+	}
1642
+
1643
+
1644
+	/**
1645
+	 * Setup an individual ticket form for the decaf event editor page
1646
+	 *
1647
+	 * @access private
1648
+	 * @param  EE_Ticket $ticket   the ticket object
1649
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1650
+	 * @param int        $row
1651
+	 * @return string generated html for the ticket row.
1652
+	 */
1653
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1654
+	{
1655
+		$template_args = array(
1656
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1657
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1658
+				: '',
1659
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1660
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1661
+			'TKT_name'            => $ticket->get('TKT_name'),
1662
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1663
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1664
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1665
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1666
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1667
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1668
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1669
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1670
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1671
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1672
+				: ' disabled=disabled',
1673
+		);
1674
+		$price = $ticket->ID() !== 0
1675
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1676
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1677
+		$price_args = array(
1678
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1679
+			'PRC_amount'            => $price->get('PRC_amount'),
1680
+			'PRT_ID'                => $price->get('PRT_ID'),
1681
+			'PRC_ID'                => $price->get('PRC_ID'),
1682
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1683
+		);
1684
+		// make sure we have default start and end dates if skeleton
1685
+		// handle rows that should NOT be empty
1686
+		if (empty($template_args['TKT_start_date'])) {
1687
+			// if empty then the start date will be now.
1688
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1689
+		}
1690
+		if (empty($template_args['TKT_end_date'])) {
1691
+			// get the earliest datetime (if present);
1692
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1693
+				? $this->_cpt_model_obj->get_first_related(
1694
+					'Datetime',
1695
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1696
+				)
1697
+				: null;
1698
+			if (! empty($earliest_dtt)) {
1699
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1700
+			} else {
1701
+				$template_args['TKT_end_date'] = date(
1702
+					'Y-m-d h:i a',
1703
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1704
+				);
1705
+			}
1706
+		}
1707
+		$template_args = array_merge($template_args, $price_args);
1708
+		$template = apply_filters(
1709
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1710
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1711
+			$ticket
1712
+		);
1713
+		return EEH_Template::display_template($template, $template_args, true);
1714
+	}
1715
+
1716
+
1717
+	/**
1718
+	 * @throws DomainException
1719
+	 */
1720
+	public function registration_options_meta_box()
1721
+	{
1722
+		$yes_no_values = array(
1723
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1724
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1725
+		);
1726
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1727
+			array(
1728
+				EEM_Registration::status_id_cancelled,
1729
+				EEM_Registration::status_id_declined,
1730
+				EEM_Registration::status_id_incomplete,
1731
+			),
1732
+			true
1733
+		);
1734
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1735
+		$template_args['_event'] = $this->_cpt_model_obj;
1736
+		$template_args['event'] = $this->_cpt_model_obj;
1737
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1738
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1739
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1740
+			'default_reg_status',
1741
+			$default_reg_status_values,
1742
+			$this->_cpt_model_obj->default_registration_status()
1743
+		);
1744
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1745
+			'display_desc',
1746
+			$yes_no_values,
1747
+			$this->_cpt_model_obj->display_description()
1748
+		);
1749
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1750
+			'display_ticket_selector',
1751
+			$yes_no_values,
1752
+			$this->_cpt_model_obj->display_ticket_selector(),
1753
+			'',
1754
+			'',
1755
+			false
1756
+		);
1757
+		$template_args['additional_registration_options'] = apply_filters(
1758
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1759
+			'',
1760
+			$template_args,
1761
+			$yes_no_values,
1762
+			$default_reg_status_values
1763
+		);
1764
+		EEH_Template::display_template(
1765
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1766
+			$template_args
1767
+		);
1768
+	}
1769
+
1770
+
1771
+	/**
1772
+	 * _get_events()
1773
+	 * This method simply returns all the events (for the given _view and paging)
1774
+	 *
1775
+	 * @access public
1776
+	 * @param int  $per_page     count of items per page (20 default);
1777
+	 * @param int  $current_page what is the current page being viewed.
1778
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1779
+	 *                           If FALSE then we return an array of event objects
1780
+	 *                           that match the given _view and paging parameters.
1781
+	 * @return array an array of event objects.
1782
+	 */
1783
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1784
+	{
1785
+		$EEME = $this->_event_model();
1786
+		$offset = ($current_page - 1) * $per_page;
1787
+		$limit = $count ? null : $offset . ',' . $per_page;
1788
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1789
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1790
+		if (isset($this->_req_data['month_range'])) {
1791
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1792
+			// simulate the FIRST day of the month, that fixes issues for months like February
1793
+			// where PHP doesn't know what to assume for date.
1794
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1795
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1796
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1797
+		}
1798
+		$where = array();
1799
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1800
+		// determine what post_status our condition will have for the query.
1801
+		switch ($status) {
1802
+			case 'month':
1803
+			case 'today':
1804
+			case null:
1805
+			case 'all':
1806
+				break;
1807
+			case 'draft':
1808
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1809
+				break;
1810
+			default:
1811
+				$where['status'] = $status;
1812
+		}
1813
+		// categories?
1814
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1815
+			? $this->_req_data['EVT_CAT'] : null;
1816
+		if (! empty($category)) {
1817
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1818
+			$where['Term_Taxonomy.term_id'] = $category;
1819
+		}
1820
+		// date where conditions
1821
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1822
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1823
+			$DateTime = new DateTime(
1824
+				$year_r . '-' . $month_r . '-01 00:00:00',
1825
+				new DateTimeZone('UTC')
1826
+			);
1827
+			$start = $DateTime->getTimestamp();
1828
+			// set the datetime to be the end of the month
1829
+			$DateTime->setDate(
1830
+				$year_r,
1831
+				$month_r,
1832
+				$DateTime->format('t')
1833
+			)->setTime(23, 59, 59);
1834
+			$end = $DateTime->getTimestamp();
1835
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1836
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1837
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1838
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1839
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1840
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1841
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1842
+			$now = date('Y-m-01');
1843
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1844
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1845
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1846
+							->setTime(23, 59, 59)
1847
+							->format(implode(' ', $start_formats));
1848
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1849
+		}
1850
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1851
+			$where['EVT_wp_user'] = get_current_user_id();
1852
+		} else {
1853
+			if (! isset($where['status'])) {
1854
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1855
+					$where['OR'] = array(
1856
+						'status*restrict_private' => array('!=', 'private'),
1857
+						'AND'                     => array(
1858
+							'status*inclusive' => array('=', 'private'),
1859
+							'EVT_wp_user'      => get_current_user_id(),
1860
+						),
1861
+					);
1862
+				}
1863
+			}
1864
+		}
1865
+		if (isset($this->_req_data['EVT_wp_user'])) {
1866
+			if (
1867
+				$this->_req_data['EVT_wp_user'] != get_current_user_id()
1868
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1869
+			) {
1870
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1871
+			}
1872
+		}
1873
+		// search query handling
1874
+		if (isset($this->_req_data['s'])) {
1875
+			$search_string = '%' . $this->_req_data['s'] . '%';
1876
+			$where['OR'] = array(
1877
+				'EVT_name'       => array('LIKE', $search_string),
1878
+				'EVT_desc'       => array('LIKE', $search_string),
1879
+				'EVT_short_desc' => array('LIKE', $search_string),
1880
+			);
1881
+		}
1882
+		// filter events by venue.
1883
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1884
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1885
+		}
1886
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1887
+		$query_params = apply_filters(
1888
+			'FHEE__Events_Admin_Page__get_events__query_params',
1889
+			array(
1890
+				$where,
1891
+				'limit'    => $limit,
1892
+				'order_by' => $orderby,
1893
+				'order'    => $order,
1894
+				'group_by' => 'EVT_ID',
1895
+			),
1896
+			$this->_req_data
1897
+		);
1898
+
1899
+		// let's first check if we have special requests coming in.
1900
+		if (isset($this->_req_data['active_status'])) {
1901
+			switch ($this->_req_data['active_status']) {
1902
+				case 'upcoming':
1903
+					return $EEME->get_upcoming_events($query_params, $count);
1904
+					break;
1905
+				case 'expired':
1906
+					return $EEME->get_expired_events($query_params, $count);
1907
+					break;
1908
+				case 'active':
1909
+					return $EEME->get_active_events($query_params, $count);
1910
+					break;
1911
+				case 'inactive':
1912
+					return $EEME->get_inactive_events($query_params, $count);
1913
+					break;
1914
+			}
1915
+		}
1916
+
1917
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1918
+		return $events;
1919
+	}
1920
+
1921
+
1922
+	/**
1923
+	 * handling for WordPress CPT actions (trash, restore, delete)
1924
+	 *
1925
+	 * @param string $post_id
1926
+	 */
1927
+	public function trash_cpt_item($post_id)
1928
+	{
1929
+		$this->_req_data['EVT_ID'] = $post_id;
1930
+		$this->_trash_or_restore_event('trash', false);
1931
+	}
1932
+
1933
+
1934
+	/**
1935
+	 * @param string $post_id
1936
+	 */
1937
+	public function restore_cpt_item($post_id)
1938
+	{
1939
+		$this->_req_data['EVT_ID'] = $post_id;
1940
+		$this->_trash_or_restore_event('draft', false);
1941
+	}
1942
+
1943
+
1944
+	/**
1945
+	 * @param string $post_id
1946
+	 */
1947
+	public function delete_cpt_item($post_id)
1948
+	{
1949
+		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1950
+		$this->_req_data['EVT_ID'] = $post_id;
1951
+		$this->_delete_event();
1952
+	}
1953
+
1954
+
1955
+	/**
1956
+	 * _trash_or_restore_event
1957
+	 *
1958
+	 * @access protected
1959
+	 * @param  string $event_status
1960
+	 * @param bool    $redirect_after
1961
+	 */
1962
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1963
+	{
1964
+		// determine the event id and set to array.
1965
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1966
+		// loop thru events
1967
+		if ($EVT_ID) {
1968
+			// clean status
1969
+			$event_status = sanitize_key($event_status);
1970
+			// grab status
1971
+			if (! empty($event_status)) {
1972
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1973
+			} else {
1974
+				$success = false;
1975
+				$msg = esc_html__(
1976
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1977
+					'event_espresso'
1978
+				);
1979
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1980
+			}
1981
+		} else {
1982
+			$success = false;
1983
+			$msg = esc_html__(
1984
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1985
+				'event_espresso'
1986
+			);
1987
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1988
+		}
1989
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1990
+		if ($redirect_after) {
1991
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1992
+		}
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * _trash_or_restore_events
1998
+	 *
1999
+	 * @access protected
2000
+	 * @param  string $event_status
2001
+	 * @return void
2002
+	 */
2003
+	protected function _trash_or_restore_events($event_status = 'trash')
2004
+	{
2005
+		// clean status
2006
+		$event_status = sanitize_key($event_status);
2007
+		// grab status
2008
+		if (! empty($event_status)) {
2009
+			$success = true;
2010
+			// determine the event id and set to array.
2011
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2012
+			// loop thru events
2013
+			foreach ($EVT_IDs as $EVT_ID) {
2014
+				if ($EVT_ID = absint($EVT_ID)) {
2015
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2016
+					$success = $results !== false ? $success : false;
2017
+				} else {
2018
+					$msg = sprintf(
2019
+						esc_html__(
2020
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2021
+							'event_espresso'
2022
+						),
2023
+						$EVT_ID
2024
+					);
2025
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2026
+					$success = false;
2027
+				}
2028
+			}
2029
+		} else {
2030
+			$success = false;
2031
+			$msg = esc_html__(
2032
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2033
+				'event_espresso'
2034
+			);
2035
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2036
+		}
2037
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2038
+		$success = $success ? 2 : false;
2039
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2040
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2041
+	}
2042
+
2043
+
2044
+	/**
2045
+	 * _trash_or_restore_events
2046
+	 *
2047
+	 * @access  private
2048
+	 * @param  int    $EVT_ID
2049
+	 * @param  string $event_status
2050
+	 * @return bool
2051
+	 */
2052
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2053
+	{
2054
+		// grab event id
2055
+		if (! $EVT_ID) {
2056
+			$msg = esc_html__(
2057
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2058
+				'event_espresso'
2059
+			);
2060
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2061
+			return false;
2062
+		}
2063
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2064
+		// clean status
2065
+		$event_status = sanitize_key($event_status);
2066
+		// grab status
2067
+		if (empty($event_status)) {
2068
+			$msg = esc_html__(
2069
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2070
+				'event_espresso'
2071
+			);
2072
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2073
+			return false;
2074
+		}
2075
+		// was event trashed or restored ?
2076
+		switch ($event_status) {
2077
+			case 'draft':
2078
+				$action = 'restored from the trash';
2079
+				$hook = 'AHEE_event_restored_from_trash';
2080
+				break;
2081
+			case 'trash':
2082
+				$action = 'moved to the trash';
2083
+				$hook = 'AHEE_event_moved_to_trash';
2084
+				break;
2085
+			default:
2086
+				$action = 'updated';
2087
+				$hook = false;
2088
+		}
2089
+		// use class to change status
2090
+		$this->_cpt_model_obj->set_status($event_status);
2091
+		$success = $this->_cpt_model_obj->save();
2092
+		if ($success === false) {
2093
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2094
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2095
+			return false;
2096
+		}
2097
+		if ($hook) {
2098
+			do_action($hook);
2099
+		}
2100
+		return true;
2101
+	}
2102
+
2103
+
2104
+	/**
2105
+	 * _delete_event
2106
+	 *
2107
+	 * @access protected
2108
+	 * @param bool $redirect_after
2109
+	 */
2110
+	protected function _delete_event()
2111
+	{
2112
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : array());
2113
+	}
2114
+
2115
+	/**
2116
+	 * Gets the tree traversal batch persister.
2117
+	 * @since 4.10.12.p
2118
+	 * @return NodeGroupDao
2119
+	 * @throws InvalidArgumentException
2120
+	 * @throws InvalidDataTypeException
2121
+	 * @throws InvalidInterfaceException
2122
+	 */
2123
+	protected function getModelObjNodeGroupPersister()
2124
+	{
2125
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2126
+			$this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2127
+		}
2128
+		return $this->model_obj_node_group_persister;
2129
+	}
2130
+
2131
+	/**
2132
+	 * _delete_events
2133
+	 *
2134
+	 * @access protected
2135
+	 * @return void
2136
+	 */
2137
+	protected function _delete_events()
2138
+	{
2139
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array());
2140
+	}
2141
+
2142
+	protected function generateDeletionPreview($event_ids)
2143
+	{
2144
+		$event_ids = (array) $event_ids;
2145
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2146
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2147
+		$return_url = EE_Admin_Page::add_query_args_and_nonce(
2148
+			[
2149
+				'action' => 'preview_deletion',
2150
+				'deletion_job_code' => $deletion_job_code,
2151
+			],
2152
+			$this->_admin_base_url
2153
+		);
2154
+		$event_ids = array_map(
2155
+			'intval',
2156
+			$event_ids
2157
+		);
2158
+
2159
+		EEH_URL::safeRedirectAndExit(
2160
+			EE_Admin_Page::add_query_args_and_nonce(
2161
+				array(
2162
+					'page'        => 'espresso_batch',
2163
+					'batch'       => EED_Batch::batch_job,
2164
+					'EVT_IDs'      => $event_ids,
2165
+					'deletion_job_code' => $deletion_job_code,
2166
+					'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2167
+					'return_url'  => urlencode($return_url),
2168
+				),
2169
+				admin_url()
2170
+			)
2171
+		);
2172
+	}
2173
+
2174
+	/**
2175
+	 * Checks for a POST submission
2176
+	 * @since 4.10.12.p
2177
+	 */
2178
+	protected function confirmDeletion()
2179
+	{
2180
+		$deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2181
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2182
+	}
2183
+
2184
+	/**
2185
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2186
+	 * @since 4.10.12.p
2187
+	 * @throws EE_Error
2188
+	 */
2189
+	protected function previewDeletion()
2190
+	{
2191
+		$preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2192
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2193
+		$this->display_admin_page_with_no_sidebar();
2194
+	}
2195
+
2196
+	/**
2197
+	 * get total number of events
2198
+	 *
2199
+	 * @access public
2200
+	 * @return int
2201
+	 */
2202
+	public function total_events()
2203
+	{
2204
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2205
+		return $count;
2206
+	}
2207
+
2208
+
2209
+	/**
2210
+	 * get total number of draft events
2211
+	 *
2212
+	 * @access public
2213
+	 * @return int
2214
+	 */
2215
+	public function total_events_draft()
2216
+	{
2217
+		$where = array(
2218
+			'status' => array('IN', array('draft', 'auto-draft')),
2219
+		);
2220
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2221
+		return $count;
2222
+	}
2223
+
2224
+
2225
+	/**
2226
+	 * get total number of trashed events
2227
+	 *
2228
+	 * @access public
2229
+	 * @return int
2230
+	 */
2231
+	public function total_trashed_events()
2232
+	{
2233
+		$where = array(
2234
+			'status' => 'trash',
2235
+		);
2236
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2237
+		return $count;
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 *    _default_event_settings
2243
+	 *    This generates the Default Settings Tab
2244
+	 *
2245
+	 * @return void
2246
+	 * @throws EE_Error
2247
+	 */
2248
+	protected function _default_event_settings()
2249
+	{
2250
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2251
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2252
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2253
+		$this->display_admin_page_with_sidebar();
2254
+	}
2255
+
2256
+
2257
+	/**
2258
+	 * Return the form for event settings.
2259
+	 *
2260
+	 * @return EE_Form_Section_Proper
2261
+	 * @throws EE_Error
2262
+	 */
2263
+	protected function _default_event_settings_form()
2264
+	{
2265
+		$registration_config = EE_Registry::instance()->CFG->registration;
2266
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2267
+			// exclude
2268
+			array(
2269
+				EEM_Registration::status_id_cancelled,
2270
+				EEM_Registration::status_id_declined,
2271
+				EEM_Registration::status_id_incomplete,
2272
+				EEM_Registration::status_id_wait_list,
2273
+			),
2274
+			true
2275
+		);
2276
+		return new EE_Form_Section_Proper(
2277
+			array(
2278
+				'name'            => 'update_default_event_settings',
2279
+				'html_id'         => 'update_default_event_settings',
2280
+				'html_class'      => 'form-table',
2281
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2282
+				'subsections'     => apply_filters(
2283
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2284
+					array(
2285
+						'default_reg_status'  => new EE_Select_Input(
2286
+							$registration_stati_for_selection,
2287
+							array(
2288
+								'default'         => isset($registration_config->default_STS_ID)
2289
+													 && array_key_exists(
2290
+														 $registration_config->default_STS_ID,
2291
+														 $registration_stati_for_selection
2292
+													 )
2293
+									? sanitize_text_field($registration_config->default_STS_ID)
2294
+									: EEM_Registration::status_id_pending_payment,
2295
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2296
+													 . EEH_Template::get_help_tab_link(
2297
+														 'default_settings_status_help_tab'
2298
+													 ),
2299
+								'html_help_text'  => esc_html__(
2300
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2301
+									'event_espresso'
2302
+								),
2303
+							)
2304
+						),
2305
+						'default_max_tickets' => new EE_Integer_Input(
2306
+							array(
2307
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2308
+									? $registration_config->default_maximum_number_of_tickets
2309
+									: EEM_Event::get_default_additional_limit(),
2310
+								'html_label_text' => esc_html__(
2311
+									'Default Maximum Tickets Allowed Per Order:',
2312
+									'event_espresso'
2313
+								)
2314
+													 . EEH_Template::get_help_tab_link(
2315
+														 'default_maximum_tickets_help_tab"'
2316
+													 ),
2317
+								'html_help_text'  => esc_html__(
2318
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2319
+									'event_espresso'
2320
+								),
2321
+							)
2322
+						),
2323
+					)
2324
+				),
2325
+			)
2326
+		);
2327
+	}
2328
+
2329
+
2330
+	/**
2331
+	 * _update_default_event_settings
2332
+	 *
2333
+	 * @access protected
2334
+	 * @return void
2335
+	 * @throws EE_Error
2336
+	 */
2337
+	protected function _update_default_event_settings()
2338
+	{
2339
+		$registration_config = EE_Registry::instance()->CFG->registration;
2340
+		$form = $this->_default_event_settings_form();
2341
+		if ($form->was_submitted()) {
2342
+			$form->receive_form_submission();
2343
+			if ($form->is_valid()) {
2344
+				$valid_data = $form->valid_data();
2345
+				if (isset($valid_data['default_reg_status'])) {
2346
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2347
+				}
2348
+				if (isset($valid_data['default_max_tickets'])) {
2349
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2350
+				}
2351
+				// update because data was valid!
2352
+				EE_Registry::instance()->CFG->update_espresso_config();
2353
+				EE_Error::overwrite_success();
2354
+				EE_Error::add_success(
2355
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2356
+				);
2357
+			}
2358
+		}
2359
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2360
+	}
2361
+
2362
+
2363
+	/*************        Templates        *************/
2364
+	protected function _template_settings()
2365
+	{
2366
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2367
+		$this->_template_args['preview_img'] = '<img src="'
2368
+											   . EVENTS_ASSETS_URL
2369
+											   . '/images/'
2370
+											   . 'caffeinated_template_features.jpg" alt="'
2371
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2372
+											   . '" />';
2373
+		$this->_template_args['preview_text'] = '<strong>'
2374
+												. esc_html__(
2375
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2376
+													'event_espresso'
2377
+												) . '</strong>';
2378
+		$this->display_admin_caf_preview_page('template_settings_tab');
2379
+	}
2380
+
2381
+
2382
+	/** Event Category Stuff **/
2383
+	/**
2384
+	 * set the _category property with the category object for the loaded page.
2385
+	 *
2386
+	 * @access private
2387
+	 * @return void
2388
+	 */
2389
+	private function _set_category_object()
2390
+	{
2391
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2392
+			return;
2393
+		} //already have the category object so get out.
2394
+		// set default category object
2395
+		$this->_set_empty_category_object();
2396
+		// only set if we've got an id
2397
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2398
+			return;
2399
+		}
2400
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2401
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2402
+		if (! empty($term)) {
2403
+			$this->_category->category_name = $term->name;
2404
+			$this->_category->category_identifier = $term->slug;
2405
+			$this->_category->category_desc = $term->description;
2406
+			$this->_category->id = $term->term_id;
2407
+			$this->_category->parent = $term->parent;
2408
+		}
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * Clears out category properties.
2414
+	 */
2415
+	private function _set_empty_category_object()
2416
+	{
2417
+		$this->_category = new stdClass();
2418
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2419
+		$this->_category->id = $this->_category->parent = 0;
2420
+	}
2421
+
2422
+
2423
+	/**
2424
+	 * @throws EE_Error
2425
+	 */
2426
+	protected function _category_list_table()
2427
+	{
2428
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2429
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2430
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2431
+			'add_category',
2432
+			'add_category',
2433
+			array(),
2434
+			'add-new-h2'
2435
+		);
2436
+		$this->display_admin_list_table_page_with_sidebar();
2437
+	}
2438
+
2439
+
2440
+	/**
2441
+	 * Output category details view.
2442
+	 */
2443
+	protected function _category_details($view)
2444
+	{
2445
+		// load formatter helper
2446
+		// load field generator helper
2447
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2448
+		$this->_set_add_edit_form_tags($route);
2449
+		$this->_set_category_object();
2450
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2451
+		$delete_action = 'delete_category';
2452
+		// custom redirect
2453
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2454
+			array('action' => 'category_list'),
2455
+			$this->_admin_base_url
2456
+		);
2457
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2458
+		// take care of contents
2459
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2460
+		$this->display_admin_page_with_sidebar();
2461
+	}
2462
+
2463
+
2464
+	/**
2465
+	 * Output category details content.
2466
+	 */
2467
+	protected function _category_details_content()
2468
+	{
2469
+		$editor_args['category_desc'] = array(
2470
+			'type'          => 'wp_editor',
2471
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2472
+			'class'         => 'my_editor_custom',
2473
+			'wpeditor_args' => array('media_buttons' => false),
2474
+		);
2475
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2476
+		$all_terms = get_terms(
2477
+			array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2478
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2479
+		);
2480
+		// setup category select for term parents.
2481
+		$category_select_values[] = array(
2482
+			'text' => esc_html__('No Parent', 'event_espresso'),
2483
+			'id'   => 0,
2484
+		);
2485
+		foreach ($all_terms as $term) {
2486
+			$category_select_values[] = array(
2487
+				'text' => $term->name,
2488
+				'id'   => $term->term_id,
2489
+			);
2490
+		}
2491
+		$category_select = EEH_Form_Fields::select_input(
2492
+			'category_parent',
2493
+			$category_select_values,
2494
+			$this->_category->parent
2495
+		);
2496
+		$template_args = array(
2497
+			'category'                 => $this->_category,
2498
+			'category_select'          => $category_select,
2499
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2500
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2501
+			'disable'                  => '',
2502
+			'disabled_message'         => false,
2503
+		);
2504
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2505
+		return EEH_Template::display_template($template, $template_args, true);
2506
+	}
2507
+
2508
+
2509
+	/**
2510
+	 * Handles deleting categories.
2511
+	 */
2512
+	protected function _delete_categories()
2513
+	{
2514
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2515
+			: (array) $this->_req_data['category_id'];
2516
+		foreach ($cat_ids as $cat_id) {
2517
+			$this->_delete_category($cat_id);
2518
+		}
2519
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2520
+		$query_args = array(
2521
+			'action' => 'category_list',
2522
+		);
2523
+		$this->_redirect_after_action(0, '', '', $query_args);
2524
+	}
2525
+
2526
+
2527
+	/**
2528
+	 * Handles deleting specific category.
2529
+	 *
2530
+	 * @param int $cat_id
2531
+	 */
2532
+	protected function _delete_category($cat_id)
2533
+	{
2534
+		$cat_id = absint($cat_id);
2535
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2536
+	}
2537
+
2538
+
2539
+	/**
2540
+	 * Handles triggering the update or insertion of a new category.
2541
+	 *
2542
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2543
+	 */
2544
+	protected function _insert_or_update_category($new_category)
2545
+	{
2546
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2547
+		$success = 0; // we already have a success message so lets not send another.
2548
+		if ($cat_id) {
2549
+			$query_args = array(
2550
+				'action'     => 'edit_category',
2551
+				'EVT_CAT_ID' => $cat_id,
2552
+			);
2553
+		} else {
2554
+			$query_args = array('action' => 'add_category');
2555
+		}
2556
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2557
+	}
2558
+
2559
+
2560
+	/**
2561
+	 * Inserts or updates category
2562
+	 *
2563
+	 * @param bool $update (true indicates we're updating a category).
2564
+	 * @return bool|mixed|string
2565
+	 */
2566
+	private function _insert_category($update = false)
2567
+	{
2568
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2569
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2570
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2571
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2572
+		if (empty($category_name)) {
2573
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2574
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2575
+			return false;
2576
+		}
2577
+		$term_args = array(
2578
+			'name'        => $category_name,
2579
+			'description' => $category_desc,
2580
+			'parent'      => $category_parent,
2581
+		);
2582
+		// was the category_identifier input disabled?
2583
+		if (isset($this->_req_data['category_identifier'])) {
2584
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2585
+		}
2586
+		$insert_ids = $update
2587
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2588
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2589
+		if (! is_array($insert_ids)) {
2590
+			$msg = esc_html__(
2591
+				'An error occurred and the category has not been saved to the database.',
2592
+				'event_espresso'
2593
+			);
2594
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2595
+		} else {
2596
+			$cat_id = $insert_ids['term_id'];
2597
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2598
+			EE_Error::add_success($msg);
2599
+		}
2600
+		return $cat_id;
2601
+	}
2602
+
2603
+
2604
+	/**
2605
+	 * Gets categories or count of categories matching the arguments in the request.
2606
+	 *
2607
+	 * @param int  $per_page
2608
+	 * @param int  $current_page
2609
+	 * @param bool $count
2610
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2611
+	 */
2612
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2613
+	{
2614
+		// testing term stuff
2615
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2616
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2617
+		$limit = ($current_page - 1) * $per_page;
2618
+		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2619
+		if (isset($this->_req_data['s'])) {
2620
+			$sstr = '%' . $this->_req_data['s'] . '%';
2621
+			$where['OR'] = array(
2622
+				'Term.name'   => array('LIKE', $sstr),
2623
+				'description' => array('LIKE', $sstr),
2624
+			);
2625
+		}
2626
+		$query_params = array(
2627
+			$where,
2628
+			'order_by'   => array($orderby => $order),
2629
+			'limit'      => $limit . ',' . $per_page,
2630
+			'force_join' => array('Term'),
2631
+		);
2632
+		$categories = $count
2633
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2634
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2635
+		return $categories;
2636
+	}
2637
+
2638
+	/* end category stuff */
2639
+	/**************/
2640
+
2641
+
2642
+	/**
2643
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2644
+	 *
2645
+	 * @throws EE_Error
2646
+	 */
2647
+	public function save_timezonestring_setting()
2648
+	{
2649
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2650
+			? $this->_req_data['timezone_selected']
2651
+			: '';
2652
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2653
+			EE_Error::add_error(
2654
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2655
+				__FILE__,
2656
+				__FUNCTION__,
2657
+				__LINE__
2658
+			);
2659
+			$this->_template_args['error'] = true;
2660
+			$this->_return_json();
2661
+		}
2662
+
2663
+		update_option('timezone_string', $timezone_string);
2664
+		EE_Error::add_success(
2665
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2666
+		);
2667
+		$this->_template_args['success'] = true;
2668
+		$this->_return_json(true, array('action' => 'create_new'));
2669
+	}
2670 2670
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Venue_View.helper.php 1 patch
Indentation   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -10,630 +10,630 @@
 block discarded – undo
10 10
 class EEH_Venue_View extends EEH_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @access    private
15
-     * @var EE_Venue
16
-     */
17
-    private static $_venue = null;
18
-
19
-
20
-    /**
21
-     *    get_venue
22
-     *    attempts to retrieve an EE_Venue object any way it can
23
-     *
24
-     * @access    public
25
-     * @param int  $VNU_ID
26
-     * @param bool $look_in_event
27
-     * @param bool $privacy_check   Defaults to true.
28
-     *                              When false, means even if the venue is private we return it regardless of access.
29
-     * @param bool $password_check
30
-     * @return EE_Venue|null
31
-     * @throws EE_Error
32
-     * @throws ReflectionException
33
-     */
34
-    public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
35
-    {
36
-        $VNU_ID = absint($VNU_ID);
37
-        // do we already have the Venue you are looking for?
38
-        if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
39
-            // If the Venue ID matches $VNU_ID, return the venue.
40
-            if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
41
-                return EEH_Venue_View::_get_venue($privacy_check);
42
-            }
43
-            // If the Venue ID does not match, try pulling a venue using $VNU_ID.
44
-            $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
45
-            if ($venue instanceof EE_Venue) {
46
-                EEH_Venue_View::$_venue = $venue;
47
-                return EEH_Venue_View::_get_venue($privacy_check);
48
-            }
49
-        }
50
-        // international newspaper?
51
-        global $post;
52
-        if ($post instanceof WP_Post) {
53
-            switch ($post->post_type) {
54
-                // if this is being called from an EE_Venue post,
55
-                // and the EE_Venue post corresponds to the EE_Venue that is being asked for,
56
-                // then we can try to just grab the attached EE_Venue object
57
-                case 'espresso_venues':
58
-                    // the post already contains the related EE_Venue object AND one of the following is TRUE:
59
-                    // the requested Venue ID matches the post ID OR...
60
-                    // there was no specific Venue ID requested
61
-                    if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
62
-                        // use existing related EE_Venue object
63
-                        EEH_Venue_View::$_venue = $post->EE_Venue;
64
-                    } elseif ($VNU_ID) {
65
-                        // there WAS a specific Venue ID requested, but it's NOT the current post object
66
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
67
-                    } else {
68
-                        // no specific Venue ID requested, so use post ID to generate EE_Venue object
69
-                        EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
70
-                    }
71
-                    break;
72
-
73
-                case 'espresso_events':
74
-                    if ($look_in_event) {
75
-                        // grab the events related venues
76
-                        $venues = EEH_Venue_View::get_event_venues();
77
-                        // make sure the result is an array
78
-                        $venues = is_array($venues) ? $venues : [];
79
-                        // do we have an ID for a specific venue?
80
-                        if ($VNU_ID) {
81
-                            // loop thru the related venues
82
-                            foreach ($venues as $venue) {
83
-                                if ($venue instanceof EE_Venue) {
84
-                                    // until we find the venue we're looking for
85
-                                    if ($venue->ID() == $VNU_ID) {
86
-                                        EEH_Venue_View::$_venue = $venue;
87
-                                        break;
88
-                                    }
89
-                                }
90
-                            }
91
-                            // no venue ID ?
92
-                            // then the global post is an events post and this function was called with no argument
93
-                        } else {
94
-                            // just grab the first related event venue
95
-                            EEH_Venue_View::$_venue = reset($venues);
96
-                        }
97
-                    }
98
-                    break;
99
-            }
100
-        }
101
-        // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
102
-        if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
103
-            // sigh... pull it from the db
104
-            EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105
-        }
106
-        return EEH_Venue_View::_get_venue($privacy_check, $password_check);
107
-    }
108
-
109
-
110
-    /**
111
-     * return a single venue
112
-     *
113
-     * @param bool $privacy_check   Defaults to true.
114
-     *                              When false, means even if the venue is private we return it regardless of access.
115
-     * @param bool $password_check
116
-     * @return  EE_Venue
117
-     * @throws EE_Error
118
-     * @throws ReflectionException
119
-     */
120
-    protected static function _get_venue($privacy_check = true, $password_check = true)
121
-    {
122
-        // check for private venues.
123
-        if (
124
-            EEH_Venue_View::$_venue instanceof EE_Venue
125
-            && EEH_Venue_View::$_venue->status() == 'private'
126
-            && $privacy_check
127
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
128
-        ) {
129
-            return null;
130
-        }
131
-        // check for password protected venues
132
-        if (
133
-            EEH_Venue_View::$_venue instanceof EE_Venue
134
-            && $password_check
135
-            && post_password_required(EEH_Venue_View::$_venue->ID())
136
-        ) {
137
-            return null;
138
-        }
139
-        return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
140
-    }
141
-
142
-
143
-    /**
144
-     *  get_event_venues
145
-     *
146
-     * @access     public
147
-     * @return     EE_Venue[]
148
-     * @throws EE_Error
149
-     * @throws ReflectionException
150
-     */
151
-    public static function get_event_venues()
152
-    {
153
-        global $post;
154
-        if ($post->post_type == 'espresso_events') {
155
-            if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
156
-                return $post->EE_Event->venues();
157
-            }
158
-        }
159
-        return [];
160
-    }
161
-
162
-
163
-    /**
164
-     * Simply checks whether a venue for the given ID (or the internally derived venue is private).
165
-     *
166
-     * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but
167
-     * is not private.  So it is important to do explicit boolean checks when using this conditional.
168
-     *
169
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
170
-     *
171
-     * @return bool|null
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     */
175
-    public static function is_venue_private($VNU_ID = false)
176
-    {
177
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
178
-        if (! $venue instanceof EE_Venue) {
179
-            return null;
180
-        }
181
-
182
-        return $venue->status() == 'private';
183
-    }
184
-
185
-
186
-    /**
187
-     * returns true or false if a venue is password protected or not
188
-     *
189
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
190
-     * @return bool
191
-     * @throws EE_Error
192
-     * @throws ReflectionException
193
-     */
194
-    public static function is_venue_password_protected($VNU_ID = false)
195
-    {
196
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
197
-        if (
198
-            $venue instanceof EE_Venue
199
-            && post_password_required($venue->ID())
200
-        ) {
201
-            return true;
202
-        }
203
-        return false;
204
-    }
205
-
206
-
207
-    /**
208
-     * If a venue is password protected, this will return the password form for gaining access
209
-     * returns an empty string otherwise
210
-     *
211
-     * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
212
-     *
213
-     * @return string
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public static function password_protected_venue_form($VNU_ID = false)
218
-    {
219
-        $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
220
-        if (
221
-            $venue instanceof EE_Venue
222
-            && post_password_required($venue->ID())
223
-        ) {
224
-            return get_the_password_form($venue->ID());
225
-        }
226
-        return '';
227
-    }
228
-
229
-
230
-    /**
231
-     *    venue_description
232
-     *
233
-     * @access    public
234
-     * @param int $VNU_ID
235
-     * @return string
236
-     * @throws EE_Error
237
-     * @throws ReflectionException
238
-     */
239
-    public static function venue_description($VNU_ID = 0)
240
-    {
241
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
242
-        if ($venue instanceof EE_Venue) {
243
-            return $venue->get_pretty('VNU_desc');
244
-        }
245
-        return '';
246
-    }
247
-
248
-
249
-    /**
250
-     *    venue_excerpt
251
-     *
252
-     * @access    public
253
-     * @param int $VNU_ID
254
-     * @return string
255
-     * @throws EE_Error
256
-     * @throws ReflectionException
257
-     */
258
-    public static function venue_excerpt($VNU_ID = 0)
259
-    {
260
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
261
-        if ($venue instanceof EE_Venue) {
262
-            $excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
263
-            $venue_link = ' ' . EEH_Venue_View::venue_details_link(
264
-                $venue->ID(),
265
-                esc_html__('more', 'event_espresso') . '&hellip;'
266
-            );
267
-            return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
268
-        }
269
-        return '';
270
-    }
271
-
272
-
273
-    /**
274
-     *    venue_categories
275
-     *
276
-     * @access    public
277
-     * @param int  $VNU_ID
278
-     * @param bool $hide_uncategorized
279
-     * @return string
280
-     * @throws EE_Error
281
-     * @throws ReflectionException
282
-     */
283
-    public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
284
-    {
285
-        $category_links = [];
286
-        $venue          = EEH_Venue_View::get_venue($VNU_ID);
287
-        if ($venue instanceof EE_Venue) {
288
-            // get category terms
289
-            if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
290
-                // loop thru terms and create links
291
-                foreach ($venue_categories as $term) {
292
-                    $url = get_term_link($term, 'espresso_venue_categories');
293
-                    if (
294
-                        ! is_wp_error($url)
295
-                        && (($hide_uncategorized
296
-                             && strtolower($term->name) != esc_html__(
297
-                                 'uncategorized',
298
-                                 'event_espresso'
299
-                             ))
300
-                            || ! $hide_uncategorized)
301
-                    ) {
302
-                        $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
303
-                    }
304
-                }
305
-            }
306
-        }
307
-        return implode(', ', $category_links);
308
-    }
309
-
310
-
311
-    /**
312
-     *    venue_address
313
-     *
314
-     * @access    public
315
-     * @param string $type
316
-     * @param int    $VNU_ID
317
-     * @param bool   $use_schema
318
-     * @param bool   $add_wrapper
319
-     * @return string
320
-     * @throws EE_Error
321
-     * @throws ReflectionException
322
-     */
323
-    public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
324
-    {
325
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
326
-        if ($venue instanceof EE_Venue) {
327
-            return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
328
-        }
329
-        return '';
330
-    }
331
-
332
-
333
-    /**
334
-     *    venue_has_address
335
-     *
336
-     * @access    public
337
-     * @param int $VNU_ID
338
-     * @return bool|string
339
-     * @throws EE_Error
340
-     * @throws ReflectionException
341
-     */
342
-    public static function venue_has_address($VNU_ID = 0)
343
-    {
344
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
345
-        if ($venue instanceof EE_Venue) {
346
-            return EEH_Address::format($venue, 'inline', false, false);
347
-        }
348
-        return false;
349
-    }
350
-
351
-
352
-    /**
353
-     *    venue_name
354
-     *
355
-     * @access    public
356
-     * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to
357
-     *                        the Venue's details page or website
358
-     * @param int    $VNU_ID
359
-     * @return string
360
-     * @throws EE_Error
361
-     * @throws ReflectionException
362
-     */
363
-    public static function venue_name($link_to = 'details', $VNU_ID = 0)
364
-    {
365
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
366
-        if ($venue instanceof EE_Venue) {
367
-            $venue_name = apply_filters(
368
-                'FHEE__EEH_Venue__venue_name__append_private_venue_name',
369
-                EEH_Venue_View::is_venue_private()
370
-                    ? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
371
-                    : EEH_Venue_View::$_venue->name(),
372
-                EEH_Venue_View::$_venue
373
-            );
374
-            $venue_name = EEH_Schema::name($venue_name);
375
-
376
-            // if venue is trashed then ignore the "link to" setting because the venue is trashed.
377
-            if ($venue->get('status') == 'trash') {
378
-                $link_to = '';
379
-            }
380
-            switch ($link_to) {
381
-                case 'details':
382
-                    return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
383
-
384
-                case 'website':
385
-                    return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
386
-
387
-                default:
388
-                    return $venue_name;
389
-            }
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-    /**
396
-     *    venue_details_link
397
-     *
398
-     * @access    public
399
-     * @param int    $VNU_ID
400
-     * @param string $text
401
-     * @return string
402
-     * @throws EE_Error
403
-     * @throws ReflectionException
404
-     */
405
-    public static function venue_details_link($VNU_ID = 0, $text = '')
406
-    {
407
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
408
-        if ($venue instanceof EE_Venue) {
409
-            return EEH_Schema::url(get_permalink($venue->ID()), $text);
410
-        }
411
-        return '';
412
-    }
413
-
414
-
415
-    /**
416
-     *    venue_website_link
417
-     *
418
-     * @access    public
419
-     * @param int    $VNU_ID
420
-     * @param string $text
421
-     * @return string
422
-     * @throws EE_Error
423
-     * @throws ReflectionException
424
-     */
425
-    public static function venue_website_link($VNU_ID = 0, $text = '')
426
-    {
427
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
428
-        if ($venue instanceof EE_Venue) {
429
-            $url  = $venue->venue_url();
430
-            $text = ! empty($text) ? $text : $url;
431
-            return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : '';
432
-        }
433
-        return '';
434
-    }
435
-
436
-
437
-    /**
438
-     *    venue_phone
439
-     *
440
-     * @access    public
441
-     * @param int $VNU_ID
442
-     * @return string
443
-     * @throws EE_Error
444
-     * @throws ReflectionException
445
-     */
446
-    public static function venue_phone($VNU_ID = 0)
447
-    {
448
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
449
-        if ($venue instanceof EE_Venue) {
450
-            return EEH_Schema::telephone($venue->phone());
451
-        }
452
-        return '';
453
-    }
454
-
455
-
456
-    /**
457
-     *    venue_gmap
458
-     *
459
-     * @access    public
460
-     * @param int         $VNU_ID
461
-     * @param bool|string $map_ID a unique identifier for this map
462
-     * @param array       $gmap   map options
463
-     * @return string
464
-     * @throws EE_Error
465
-     * @throws ReflectionException
466
-     */
467
-    public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [])
468
-    {
469
-
470
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
471
-        if ($venue instanceof EE_Venue) {
472
-            // check for global espresso_events post and use it's ID if no map_ID is set
473
-            global $post;
474
-            $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
475
-            // grab map settings
476
-            $map_cfg = EE_Registry::instance()->CFG->map_settings;
477
-            // are maps enabled ?
478
-            if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
479
-                $details_page = is_single();
480
-                $options      = [];
481
-
482
-                $options['map_ID'] = $map_ID && $map_ID != $venue->ID()
483
-                    ? $map_ID . '-' . $venue->ID()
484
-                    : $venue->ID();
485
-
486
-                $options['location'] = EEH_Address::format($venue, 'inline', false, false);
487
-
488
-                $options['ee_map_width'] = $details_page
489
-                    ? $map_cfg->event_details_map_width
490
-                    : $map_cfg->event_list_map_width;
491
-
492
-                $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width'])
493
-                    ? $gmap['ee_map_width']
494
-                    : $options['ee_map_width'];
495
-
496
-                $options['ee_map_height'] = $details_page
497
-                    ? $map_cfg->event_details_map_height
498
-                    : $map_cfg->event_list_map_height;
499
-
500
-                $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height'])
501
-                    ? $gmap['ee_map_height']
502
-                    : $options['ee_map_height'];
503
-
504
-                $options['ee_map_zoom'] = $details_page
505
-                    ? $map_cfg->event_details_map_zoom
506
-                    : $map_cfg->event_list_map_zoom;
507
-
508
-                $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom'])
509
-                    ? $gmap['ee_map_zoom']
510
-                    : $options['ee_map_zoom'];
511
-
512
-                $options['ee_map_nav_display'] = $details_page
513
-                    ? $map_cfg->event_details_display_nav
514
-                    : $map_cfg->event_list_display_nav;
515
-
516
-                $options['ee_map_nav_display'] =
517
-                    isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display'])
518
-                        ? 'true'
519
-                        : $options['ee_map_nav_display'];
520
-
521
-                $options['ee_map_nav_size'] = $details_page
522
-                    ? $map_cfg->event_details_nav_size
523
-                    : $map_cfg->event_list_nav_size;
524
-
525
-                $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])
526
-                    ? $gmap['ee_map_nav_size']
527
-                    : $options['ee_map_nav_size'];
528
-
529
-                $options['ee_map_type_control'] = $details_page
530
-                    ? $map_cfg->event_details_control_type
531
-                    : $map_cfg->event_list_control_type;
532
-
533
-                $options['ee_map_type_control'] =
534
-                    isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])
535
-                        ? $gmap['ee_map_type_control']
536
-                        : $options['ee_map_type_control'];
537
-
538
-                $options['ee_map_align'] = $details_page
539
-                    ? $map_cfg->event_details_map_align
540
-                    : $map_cfg->event_list_map_align;
541
-
542
-                $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])
543
-                    ? $gmap['ee_map_align']
544
-                    : $options['ee_map_align'];
545
-
546
-                $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url'])
547
-                    ? (bool) absint($gmap['ee_static_url'])
548
-                    : $venue->google_map_link();
549
-
550
-                return EEH_Maps::google_map($options);
551
-            }
552
-        }
553
-
554
-        return '';
555
-    }
556
-
557
-
558
-    /**
559
-     * Gets the HTML to display a static map of the venue
560
-     *
561
-     * @param EE_Venue $venue
562
-     * @param array    $attributes like EEH_Maps::google_map_link
563
-     * @return string
564
-     * @throws EE_Error
565
-     * @throws ReflectionException
566
-     */
567
-    public static function espresso_google_static_map(EE_Venue $venue, $attributes = [])
568
-    {
569
-        $state      = $venue->state_obj();
570
-        $country    = $venue->country_obj();
571
-        $attributes = shortcode_atts(
572
-            [
573
-                'id'      => $venue->ID(),
574
-                'address' => $venue->get('VNU_address'),
575
-                'city'    => $venue->get('VNU_city'),
576
-                'state'   => $state instanceof EE_State ? $state->name() : '',
577
-                'zip'     => $venue->get('VNU_zip'),
578
-                'country' => $country instanceof EE_Country ? $country->name() : '',
579
-                'type'    => 'map',
580
-                'map_w'   => 200,
581
-                'map_h'   => 200,
582
-            ],
583
-            $attributes
584
-        );
585
-        return EEH_Maps::google_map_link($attributes);
586
-    }
587
-
588
-
589
-    /**
590
-     *    edit_venue_link
591
-     *
592
-     * @access    public
593
-     * @param int    $VNU_ID
594
-     * @param string $link
595
-     * @param string $before
596
-     * @param string $after
597
-     * @return string
598
-     * @throws EE_Error
599
-     * @throws ReflectionException
600
-     */
601
-    public static function edit_venue_link(
602
-        $VNU_ID = 0,
603
-        $link = '',
604
-        $before = '<p class="edit-venue-lnk small-txt">',
605
-        $after = '</p>'
606
-    ) {
607
-        $venue = EEH_Venue_View::get_venue($VNU_ID);
608
-        if ($venue instanceof EE_Venue) {
609
-            // can the user edit this post ?
610
-            if (current_user_can('edit_post', $venue->ID())) {
611
-                // set link text
612
-                $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso');
613
-                // generate nonce
614
-                $nonce = wp_create_nonce('edit_nonce');
615
-                // generate url to venue editor for this venue
616
-                $url =
617
-                    add_query_arg(
618
-                        [
619
-                            'page'       => 'espresso_venues',
620
-                            'action'     => 'edit',
621
-                            'post'       => $venue->ID(),
622
-                            'edit_nonce' => $nonce,
623
-                        ],
624
-                        admin_url('admin.php')
625
-                    );
626
-                // get edit CPT text
627
-                $post_type_obj = get_post_type_object('espresso_venues');
628
-                // build final link html
629
-                $link =
630
-                    '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
631
-                        $post_type_obj->labels->edit_item
632
-                    ) . '">' . $link . '</a>';
633
-                // put it all together
634
-                return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
635
-            }
636
-        }
637
-        return '';
638
-    }
13
+	/**
14
+	 * @access    private
15
+	 * @var EE_Venue
16
+	 */
17
+	private static $_venue = null;
18
+
19
+
20
+	/**
21
+	 *    get_venue
22
+	 *    attempts to retrieve an EE_Venue object any way it can
23
+	 *
24
+	 * @access    public
25
+	 * @param int  $VNU_ID
26
+	 * @param bool $look_in_event
27
+	 * @param bool $privacy_check   Defaults to true.
28
+	 *                              When false, means even if the venue is private we return it regardless of access.
29
+	 * @param bool $password_check
30
+	 * @return EE_Venue|null
31
+	 * @throws EE_Error
32
+	 * @throws ReflectionException
33
+	 */
34
+	public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true)
35
+	{
36
+		$VNU_ID = absint($VNU_ID);
37
+		// do we already have the Venue you are looking for?
38
+		if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
39
+			// If the Venue ID matches $VNU_ID, return the venue.
40
+			if (EEH_Venue_View::$_venue->ID() === $VNU_ID) {
41
+				return EEH_Venue_View::_get_venue($privacy_check);
42
+			}
43
+			// If the Venue ID does not match, try pulling a venue using $VNU_ID.
44
+			$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
45
+			if ($venue instanceof EE_Venue) {
46
+				EEH_Venue_View::$_venue = $venue;
47
+				return EEH_Venue_View::_get_venue($privacy_check);
48
+			}
49
+		}
50
+		// international newspaper?
51
+		global $post;
52
+		if ($post instanceof WP_Post) {
53
+			switch ($post->post_type) {
54
+				// if this is being called from an EE_Venue post,
55
+				// and the EE_Venue post corresponds to the EE_Venue that is being asked for,
56
+				// then we can try to just grab the attached EE_Venue object
57
+				case 'espresso_venues':
58
+					// the post already contains the related EE_Venue object AND one of the following is TRUE:
59
+					// the requested Venue ID matches the post ID OR...
60
+					// there was no specific Venue ID requested
61
+					if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) {
62
+						// use existing related EE_Venue object
63
+						EEH_Venue_View::$_venue = $post->EE_Venue;
64
+					} elseif ($VNU_ID) {
65
+						// there WAS a specific Venue ID requested, but it's NOT the current post object
66
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
67
+					} else {
68
+						// no specific Venue ID requested, so use post ID to generate EE_Venue object
69
+						EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID);
70
+					}
71
+					break;
72
+
73
+				case 'espresso_events':
74
+					if ($look_in_event) {
75
+						// grab the events related venues
76
+						$venues = EEH_Venue_View::get_event_venues();
77
+						// make sure the result is an array
78
+						$venues = is_array($venues) ? $venues : [];
79
+						// do we have an ID for a specific venue?
80
+						if ($VNU_ID) {
81
+							// loop thru the related venues
82
+							foreach ($venues as $venue) {
83
+								if ($venue instanceof EE_Venue) {
84
+									// until we find the venue we're looking for
85
+									if ($venue->ID() == $VNU_ID) {
86
+										EEH_Venue_View::$_venue = $venue;
87
+										break;
88
+									}
89
+								}
90
+							}
91
+							// no venue ID ?
92
+							// then the global post is an events post and this function was called with no argument
93
+						} else {
94
+							// just grab the first related event venue
95
+							EEH_Venue_View::$_venue = reset($venues);
96
+						}
97
+					}
98
+					break;
99
+			}
100
+		}
101
+		// now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID...
102
+		if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) {
103
+			// sigh... pull it from the db
104
+			EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
105
+		}
106
+		return EEH_Venue_View::_get_venue($privacy_check, $password_check);
107
+	}
108
+
109
+
110
+	/**
111
+	 * return a single venue
112
+	 *
113
+	 * @param bool $privacy_check   Defaults to true.
114
+	 *                              When false, means even if the venue is private we return it regardless of access.
115
+	 * @param bool $password_check
116
+	 * @return  EE_Venue
117
+	 * @throws EE_Error
118
+	 * @throws ReflectionException
119
+	 */
120
+	protected static function _get_venue($privacy_check = true, $password_check = true)
121
+	{
122
+		// check for private venues.
123
+		if (
124
+			EEH_Venue_View::$_venue instanceof EE_Venue
125
+			&& EEH_Venue_View::$_venue->status() == 'private'
126
+			&& $privacy_check
127
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')
128
+		) {
129
+			return null;
130
+		}
131
+		// check for password protected venues
132
+		if (
133
+			EEH_Venue_View::$_venue instanceof EE_Venue
134
+			&& $password_check
135
+			&& post_password_required(EEH_Venue_View::$_venue->ID())
136
+		) {
137
+			return null;
138
+		}
139
+		return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null;
140
+	}
141
+
142
+
143
+	/**
144
+	 *  get_event_venues
145
+	 *
146
+	 * @access     public
147
+	 * @return     EE_Venue[]
148
+	 * @throws EE_Error
149
+	 * @throws ReflectionException
150
+	 */
151
+	public static function get_event_venues()
152
+	{
153
+		global $post;
154
+		if ($post->post_type == 'espresso_events') {
155
+			if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) {
156
+				return $post->EE_Event->venues();
157
+			}
158
+		}
159
+		return [];
160
+	}
161
+
162
+
163
+	/**
164
+	 * Simply checks whether a venue for the given ID (or the internally derived venue is private).
165
+	 *
166
+	 * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but
167
+	 * is not private.  So it is important to do explicit boolean checks when using this conditional.
168
+	 *
169
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
170
+	 *
171
+	 * @return bool|null
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 */
175
+	public static function is_venue_private($VNU_ID = false)
176
+	{
177
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
178
+		if (! $venue instanceof EE_Venue) {
179
+			return null;
180
+		}
181
+
182
+		return $venue->status() == 'private';
183
+	}
184
+
185
+
186
+	/**
187
+	 * returns true or false if a venue is password protected or not
188
+	 *
189
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
190
+	 * @return bool
191
+	 * @throws EE_Error
192
+	 * @throws ReflectionException
193
+	 */
194
+	public static function is_venue_password_protected($VNU_ID = false)
195
+	{
196
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
197
+		if (
198
+			$venue instanceof EE_Venue
199
+			&& post_password_required($venue->ID())
200
+		) {
201
+			return true;
202
+		}
203
+		return false;
204
+	}
205
+
206
+
207
+	/**
208
+	 * If a venue is password protected, this will return the password form for gaining access
209
+	 * returns an empty string otherwise
210
+	 *
211
+	 * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object.
212
+	 *
213
+	 * @return string
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public static function password_protected_venue_form($VNU_ID = false)
218
+	{
219
+		$venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false);
220
+		if (
221
+			$venue instanceof EE_Venue
222
+			&& post_password_required($venue->ID())
223
+		) {
224
+			return get_the_password_form($venue->ID());
225
+		}
226
+		return '';
227
+	}
228
+
229
+
230
+	/**
231
+	 *    venue_description
232
+	 *
233
+	 * @access    public
234
+	 * @param int $VNU_ID
235
+	 * @return string
236
+	 * @throws EE_Error
237
+	 * @throws ReflectionException
238
+	 */
239
+	public static function venue_description($VNU_ID = 0)
240
+	{
241
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
242
+		if ($venue instanceof EE_Venue) {
243
+			return $venue->get_pretty('VNU_desc');
244
+		}
245
+		return '';
246
+	}
247
+
248
+
249
+	/**
250
+	 *    venue_excerpt
251
+	 *
252
+	 * @access    public
253
+	 * @param int $VNU_ID
254
+	 * @return string
255
+	 * @throws EE_Error
256
+	 * @throws ReflectionException
257
+	 */
258
+	public static function venue_excerpt($VNU_ID = 0)
259
+	{
260
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
261
+		if ($venue instanceof EE_Venue) {
262
+			$excerpt    = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description();
263
+			$venue_link = ' ' . EEH_Venue_View::venue_details_link(
264
+				$venue->ID(),
265
+				esc_html__('more', 'event_espresso') . '&hellip;'
266
+			);
267
+			return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : '';
268
+		}
269
+		return '';
270
+	}
271
+
272
+
273
+	/**
274
+	 *    venue_categories
275
+	 *
276
+	 * @access    public
277
+	 * @param int  $VNU_ID
278
+	 * @param bool $hide_uncategorized
279
+	 * @return string
280
+	 * @throws EE_Error
281
+	 * @throws ReflectionException
282
+	 */
283
+	public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true)
284
+	{
285
+		$category_links = [];
286
+		$venue          = EEH_Venue_View::get_venue($VNU_ID);
287
+		if ($venue instanceof EE_Venue) {
288
+			// get category terms
289
+			if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) {
290
+				// loop thru terms and create links
291
+				foreach ($venue_categories as $term) {
292
+					$url = get_term_link($term, 'espresso_venue_categories');
293
+					if (
294
+						! is_wp_error($url)
295
+						&& (($hide_uncategorized
296
+							 && strtolower($term->name) != esc_html__(
297
+								 'uncategorized',
298
+								 'event_espresso'
299
+							 ))
300
+							|| ! $hide_uncategorized)
301
+					) {
302
+						$category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> ';
303
+					}
304
+				}
305
+			}
306
+		}
307
+		return implode(', ', $category_links);
308
+	}
309
+
310
+
311
+	/**
312
+	 *    venue_address
313
+	 *
314
+	 * @access    public
315
+	 * @param string $type
316
+	 * @param int    $VNU_ID
317
+	 * @param bool   $use_schema
318
+	 * @param bool   $add_wrapper
319
+	 * @return string
320
+	 * @throws EE_Error
321
+	 * @throws ReflectionException
322
+	 */
323
+	public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true)
324
+	{
325
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
326
+		if ($venue instanceof EE_Venue) {
327
+			return EEH_Address::format($venue, $type, $use_schema, $add_wrapper);
328
+		}
329
+		return '';
330
+	}
331
+
332
+
333
+	/**
334
+	 *    venue_has_address
335
+	 *
336
+	 * @access    public
337
+	 * @param int $VNU_ID
338
+	 * @return bool|string
339
+	 * @throws EE_Error
340
+	 * @throws ReflectionException
341
+	 */
342
+	public static function venue_has_address($VNU_ID = 0)
343
+	{
344
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
345
+		if ($venue instanceof EE_Venue) {
346
+			return EEH_Address::format($venue, 'inline', false, false);
347
+		}
348
+		return false;
349
+	}
350
+
351
+
352
+	/**
353
+	 *    venue_name
354
+	 *
355
+	 * @access    public
356
+	 * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to
357
+	 *                        the Venue's details page or website
358
+	 * @param int    $VNU_ID
359
+	 * @return string
360
+	 * @throws EE_Error
361
+	 * @throws ReflectionException
362
+	 */
363
+	public static function venue_name($link_to = 'details', $VNU_ID = 0)
364
+	{
365
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
366
+		if ($venue instanceof EE_Venue) {
367
+			$venue_name = apply_filters(
368
+				'FHEE__EEH_Venue__venue_name__append_private_venue_name',
369
+				EEH_Venue_View::is_venue_private()
370
+					? EEH_Venue_View::$_venue->name() . "&nbsp;" . esc_html__('(Private)', 'event_espresso')
371
+					: EEH_Venue_View::$_venue->name(),
372
+				EEH_Venue_View::$_venue
373
+			);
374
+			$venue_name = EEH_Schema::name($venue_name);
375
+
376
+			// if venue is trashed then ignore the "link to" setting because the venue is trashed.
377
+			if ($venue->get('status') == 'trash') {
378
+				$link_to = '';
379
+			}
380
+			switch ($link_to) {
381
+				case 'details':
382
+					return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name);
383
+
384
+				case 'website':
385
+					return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name);
386
+
387
+				default:
388
+					return $venue_name;
389
+			}
390
+		}
391
+		return '';
392
+	}
393
+
394
+
395
+	/**
396
+	 *    venue_details_link
397
+	 *
398
+	 * @access    public
399
+	 * @param int    $VNU_ID
400
+	 * @param string $text
401
+	 * @return string
402
+	 * @throws EE_Error
403
+	 * @throws ReflectionException
404
+	 */
405
+	public static function venue_details_link($VNU_ID = 0, $text = '')
406
+	{
407
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
408
+		if ($venue instanceof EE_Venue) {
409
+			return EEH_Schema::url(get_permalink($venue->ID()), $text);
410
+		}
411
+		return '';
412
+	}
413
+
414
+
415
+	/**
416
+	 *    venue_website_link
417
+	 *
418
+	 * @access    public
419
+	 * @param int    $VNU_ID
420
+	 * @param string $text
421
+	 * @return string
422
+	 * @throws EE_Error
423
+	 * @throws ReflectionException
424
+	 */
425
+	public static function venue_website_link($VNU_ID = 0, $text = '')
426
+	{
427
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
428
+		if ($venue instanceof EE_Venue) {
429
+			$url  = $venue->venue_url();
430
+			$text = ! empty($text) ? $text : $url;
431
+			return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : '';
432
+		}
433
+		return '';
434
+	}
435
+
436
+
437
+	/**
438
+	 *    venue_phone
439
+	 *
440
+	 * @access    public
441
+	 * @param int $VNU_ID
442
+	 * @return string
443
+	 * @throws EE_Error
444
+	 * @throws ReflectionException
445
+	 */
446
+	public static function venue_phone($VNU_ID = 0)
447
+	{
448
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
449
+		if ($venue instanceof EE_Venue) {
450
+			return EEH_Schema::telephone($venue->phone());
451
+		}
452
+		return '';
453
+	}
454
+
455
+
456
+	/**
457
+	 *    venue_gmap
458
+	 *
459
+	 * @access    public
460
+	 * @param int         $VNU_ID
461
+	 * @param bool|string $map_ID a unique identifier for this map
462
+	 * @param array       $gmap   map options
463
+	 * @return string
464
+	 * @throws EE_Error
465
+	 * @throws ReflectionException
466
+	 */
467
+	public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [])
468
+	{
469
+
470
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
471
+		if ($venue instanceof EE_Venue) {
472
+			// check for global espresso_events post and use it's ID if no map_ID is set
473
+			global $post;
474
+			$map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID;
475
+			// grab map settings
476
+			$map_cfg = EE_Registry::instance()->CFG->map_settings;
477
+			// are maps enabled ?
478
+			if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) {
479
+				$details_page = is_single();
480
+				$options      = [];
481
+
482
+				$options['map_ID'] = $map_ID && $map_ID != $venue->ID()
483
+					? $map_ID . '-' . $venue->ID()
484
+					: $venue->ID();
485
+
486
+				$options['location'] = EEH_Address::format($venue, 'inline', false, false);
487
+
488
+				$options['ee_map_width'] = $details_page
489
+					? $map_cfg->event_details_map_width
490
+					: $map_cfg->event_list_map_width;
491
+
492
+				$options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width'])
493
+					? $gmap['ee_map_width']
494
+					: $options['ee_map_width'];
495
+
496
+				$options['ee_map_height'] = $details_page
497
+					? $map_cfg->event_details_map_height
498
+					: $map_cfg->event_list_map_height;
499
+
500
+				$options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height'])
501
+					? $gmap['ee_map_height']
502
+					: $options['ee_map_height'];
503
+
504
+				$options['ee_map_zoom'] = $details_page
505
+					? $map_cfg->event_details_map_zoom
506
+					: $map_cfg->event_list_map_zoom;
507
+
508
+				$options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom'])
509
+					? $gmap['ee_map_zoom']
510
+					: $options['ee_map_zoom'];
511
+
512
+				$options['ee_map_nav_display'] = $details_page
513
+					? $map_cfg->event_details_display_nav
514
+					: $map_cfg->event_list_display_nav;
515
+
516
+				$options['ee_map_nav_display'] =
517
+					isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display'])
518
+						? 'true'
519
+						: $options['ee_map_nav_display'];
520
+
521
+				$options['ee_map_nav_size'] = $details_page
522
+					? $map_cfg->event_details_nav_size
523
+					: $map_cfg->event_list_nav_size;
524
+
525
+				$options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size'])
526
+					? $gmap['ee_map_nav_size']
527
+					: $options['ee_map_nav_size'];
528
+
529
+				$options['ee_map_type_control'] = $details_page
530
+					? $map_cfg->event_details_control_type
531
+					: $map_cfg->event_list_control_type;
532
+
533
+				$options['ee_map_type_control'] =
534
+					isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control'])
535
+						? $gmap['ee_map_type_control']
536
+						: $options['ee_map_type_control'];
537
+
538
+				$options['ee_map_align'] = $details_page
539
+					? $map_cfg->event_details_map_align
540
+					: $map_cfg->event_list_map_align;
541
+
542
+				$options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align'])
543
+					? $gmap['ee_map_align']
544
+					: $options['ee_map_align'];
545
+
546
+				$options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url'])
547
+					? (bool) absint($gmap['ee_static_url'])
548
+					: $venue->google_map_link();
549
+
550
+				return EEH_Maps::google_map($options);
551
+			}
552
+		}
553
+
554
+		return '';
555
+	}
556
+
557
+
558
+	/**
559
+	 * Gets the HTML to display a static map of the venue
560
+	 *
561
+	 * @param EE_Venue $venue
562
+	 * @param array    $attributes like EEH_Maps::google_map_link
563
+	 * @return string
564
+	 * @throws EE_Error
565
+	 * @throws ReflectionException
566
+	 */
567
+	public static function espresso_google_static_map(EE_Venue $venue, $attributes = [])
568
+	{
569
+		$state      = $venue->state_obj();
570
+		$country    = $venue->country_obj();
571
+		$attributes = shortcode_atts(
572
+			[
573
+				'id'      => $venue->ID(),
574
+				'address' => $venue->get('VNU_address'),
575
+				'city'    => $venue->get('VNU_city'),
576
+				'state'   => $state instanceof EE_State ? $state->name() : '',
577
+				'zip'     => $venue->get('VNU_zip'),
578
+				'country' => $country instanceof EE_Country ? $country->name() : '',
579
+				'type'    => 'map',
580
+				'map_w'   => 200,
581
+				'map_h'   => 200,
582
+			],
583
+			$attributes
584
+		);
585
+		return EEH_Maps::google_map_link($attributes);
586
+	}
587
+
588
+
589
+	/**
590
+	 *    edit_venue_link
591
+	 *
592
+	 * @access    public
593
+	 * @param int    $VNU_ID
594
+	 * @param string $link
595
+	 * @param string $before
596
+	 * @param string $after
597
+	 * @return string
598
+	 * @throws EE_Error
599
+	 * @throws ReflectionException
600
+	 */
601
+	public static function edit_venue_link(
602
+		$VNU_ID = 0,
603
+		$link = '',
604
+		$before = '<p class="edit-venue-lnk small-txt">',
605
+		$after = '</p>'
606
+	) {
607
+		$venue = EEH_Venue_View::get_venue($VNU_ID);
608
+		if ($venue instanceof EE_Venue) {
609
+			// can the user edit this post ?
610
+			if (current_user_can('edit_post', $venue->ID())) {
611
+				// set link text
612
+				$link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso');
613
+				// generate nonce
614
+				$nonce = wp_create_nonce('edit_nonce');
615
+				// generate url to venue editor for this venue
616
+				$url =
617
+					add_query_arg(
618
+						[
619
+							'page'       => 'espresso_venues',
620
+							'action'     => 'edit',
621
+							'post'       => $venue->ID(),
622
+							'edit_nonce' => $nonce,
623
+						],
624
+						admin_url('admin.php')
625
+					);
626
+				// get edit CPT text
627
+				$post_type_obj = get_post_type_object('espresso_venues');
628
+				// build final link html
629
+				$link =
630
+					'<a class="post-edit-link" href="' . $url . '" title="' . esc_attr(
631
+						$post_type_obj->labels->edit_item
632
+					) . '">' . $link . '</a>';
633
+				// put it all together
634
+				return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after;
635
+			}
636
+		}
637
+		return '';
638
+	}
639 639
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Schema.helper.php 2 patches
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -12,298 +12,298 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * generates JSON-based linked data for an event
17
-     *
18
-     * @param EE_Event $event
19
-     * @throws EE_Error
20
-     */
21
-    public static function add_json_linked_data_for_event(EE_Event $event)
22
-    {
23
-        // Check we have a valid datetime for the event
24
-        if (! $event->primary_datetime() instanceof EE_Datetime) {
25
-            return;
26
-        }
27
-
28
-        $template_args = array(
29
-            'event_permalink' => '',
30
-            'event_name' => '',
31
-            'event_description' => '',
32
-            'event_start' => '',
33
-            'event_end' => '',
34
-            'event_attendance_mode' => '',
35
-            'event_status' => '',
36
-            'currency' => '',
37
-            'event_tickets' => array(),
38
-            'venue_name' => '',
39
-            'venue_url' => '',
40
-            'venue_locality' => '',
41
-            'venue_region' => '',
42
-            'venue_address' => '',
43
-            'event_image' => '',
44
-        );
45
-        $template_args['event_permalink'] = $event->get_permalink();
46
-        $template_args['event_name'] = $event->name();
47
-        $template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
48
-        // clone datetime so that date formats don't override those for the original datetime
49
-        $primary_datetime = clone $event->primary_datetime();
50
-        $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM);
51
-        $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM);
52
-        unset($primary_datetime);
53
-        switch ($event->status()) {
54
-            case EEM_Event::cancelled:
55
-                $event_status = 'EventCancelled';
56
-                break;
57
-            case EEM_Event::postponed:
58
-                $event_status = 'EventPostponed';
59
-                break;
60
-            default:
61
-                $event_status = 'EventScheduled';
62
-        }
63
-        $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode';
64
-        $template_args['event_status'] = '"https://schema.org/' . $event_status . '"';
65
-        $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
66
-        foreach ($event->tickets() as $original_ticket) {
67
-            // clone tickets so that date formats don't override those for the original ticket
68
-            $ticket = clone $original_ticket;
69
-            $ID = $ticket->ID();
70
-            $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
-            $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
-            $template_args['event_tickets'][ $ID ]['price'] = number_format(
73
-                $ticket->price(),
74
-                EE_Registry::instance()->CFG->currency->dec_plc,
75
-                EE_Registry::instance()->CFG->currency->dec_mrk,
76
-                ''
77
-            );
78
-            switch ($ticket->ticket_status()) {
79
-                case 'TKO':
80
-                    $availability = 'InStock';
81
-                    break;
82
-                case 'TKS':
83
-                    $availability = 'SoldOut';
84
-                    break;
85
-                default:
86
-                    $availability = null;
87
-                    break;
88
-            }
89
-            $template_args['event_tickets'][ $ID ]['availability'] = $availability;
90
-            unset($ticket);
91
-        }
92
-        $VNU_ID = espresso_venue_id();
93
-        if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
94
-            $venue = EEH_Venue_View::get_venue($VNU_ID);
95
-            $template_args['venue_name'] = get_the_title($VNU_ID);
96
-            $template_args['venue_url'] = get_permalink($VNU_ID);
97
-            $template_args['venue_locality'] = $venue->city();
98
-            $template_args['venue_region'] = $venue->state_name();
99
-            $template_args['venue_address'] = $venue->address();
100
-            if ($venue->virtual_url() !== '') {
101
-                $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode';
102
-            }
103
-            if ($venue->virtual_url() !== '' && $venue->address() !== '') {
104
-                $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode';
105
-            }
106
-        }
107
-        $template_args['event_image'] = $event->feature_image_url();
108
-        $template_args = apply_filters(
109
-            'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
110
-            $template_args,
111
-            $event,
112
-            $VNU_ID
113
-        );
114
-        extract($template_args, EXTR_OVERWRITE);
115
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
116
-    }
117
-
118
-
119
-    /**
120
-     *    location
121
-     *    The location of the event, organization or action.
122
-     *    Should include the Venue name AND schema formatted address info
123
-     *
124
-     * @access public
125
-     * @param string $location
126
-     * @return string
127
-     */
128
-    public static function location($location = null)
129
-    {
130
-        return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
131
-                                      . $location
132
-                                      . '</div>' : '';
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     *    name
139
-     *    The name of the Event or Venue.
140
-     *
141
-     * @access public
142
-     * @param string $name
143
-     * @return string
144
-     */
145
-    public static function name($name = null)
146
-    {
147
-        return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : '';
148
-    }
149
-
150
-
151
-
152
-    /**
153
-     *    streetAddress
154
-     *    The street address. For example, 1600 Amphitheatre Pkwy.
155
-     *
156
-     * @access public
157
-     * @param EEI_Address $obj_with_address
158
-     * @return string
159
-     */
160
-    public static function streetAddress(EEI_Address $obj_with_address = null)
161
-    {
162
-        return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
163
-            ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     *    postOfficeBoxNumber
170
-     *    The post office box number for PO box addresses.
171
-     *
172
-     * @access public
173
-     * @param EEI_Address $obj_with_address
174
-     * @return string
175
-     */
176
-    public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null)
177
-    {
178
-        // regex check for some form of PO Box or P.O. Box, etc, etc, etc
179
-        if (
180
-            preg_match(
181
-                "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
182
-                $obj_with_address->address2()
183
-            )
184
-        ) {
185
-            return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
186
-                ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
187
-        } else {
188
-            return $obj_with_address->address2();
189
-        }
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     *    addressLocality
196
-     *    The locality (city, town, etc). For example, Mountain View.
197
-     *
198
-     * @access public
199
-     * @param EEI_Address $obj_with_address
200
-     * @return string
201
-     */
202
-    public static function addressLocality(EEI_Address $obj_with_address = null)
203
-    {
204
-        return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
205
-            ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     *    addressRegion
212
-     *    The region (state, province, etc). For example, CA.
213
-     *
214
-     * @access public
215
-     * @param EEI_Address $obj_with_address
216
-     * @return string
217
-     */
218
-    public static function addressRegion(EEI_Address $obj_with_address = null)
219
-    {
220
-        $state = $obj_with_address->state_name();
221
-        if (! empty($state)) {
222
-            return '<span itemprop="addressRegion">' . $state . '</span>';
223
-        } else {
224
-            return '';
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     *    addressCountry
232
-     *    The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code.
233
-     *
234
-     * @access public
235
-     * @param EEI_Address $obj_with_address
236
-     * @return string
237
-     */
238
-    public static function addressCountry(EEI_Address $obj_with_address = null)
239
-    {
240
-        $country = $obj_with_address->country_name();
241
-        if (! empty($country)) {
242
-            return '<span itemprop="addressCountry">' . $country . '</span>';
243
-        } else {
244
-            return '';
245
-        }
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     *    postalCode
252
-     *    The postal code. For example, 94043.
253
-     *
254
-     * @access public
255
-     * @param EEI_Address $obj_with_address
256
-     * @return string
257
-     */
258
-    public static function postalCode(EEI_Address $obj_with_address = null)
259
-    {
260
-        return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
261
-                                                                                      . $obj_with_address->zip()
262
-                                                                                      . '</span>' : '';
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     *    telephone
269
-     *    The telephone number.
270
-     *
271
-     * @access public
272
-     * @param string $phone_nmbr
273
-     * @return string
274
-     */
275
-    public static function telephone($phone_nmbr = null)
276
-    {
277
-        return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
278
-            : '';
279
-    }
280
-
281
-
282
-
283
-    /**
284
-     *    URL
285
-     *    URL of the item as a clickable link
286
-     *
287
-     * @access public
288
-     * @param string $url        - the URL that the link will resolve to
289
-     * @param string $text       - the text that will be used for the visible link
290
-     * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
291
-     * @return string (link)
292
-     */
293
-    public static function url($url = null, $text = null, $attributes = array())
294
-    {
295
-        // Check the URL includes a scheme
296
-        $parsed_url = parse_url($url);
297
-        if (empty($parsed_url['scheme'])) {
298
-            $url = 'https://' . ltrim($url, '/');
299
-        }
300
-        $atts = '';
301
-        foreach ($attributes as $attribute => $value) {
302
-            $atts .= ' ' . $attribute . '="' . $value . '"';
303
-        }
304
-        $text = $text !== null && $text !== '' ? $text : esc_url($url);
305
-        return ! empty($url)
306
-            ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>'
307
-            : '';
308
-    }
15
+	/**
16
+	 * generates JSON-based linked data for an event
17
+	 *
18
+	 * @param EE_Event $event
19
+	 * @throws EE_Error
20
+	 */
21
+	public static function add_json_linked_data_for_event(EE_Event $event)
22
+	{
23
+		// Check we have a valid datetime for the event
24
+		if (! $event->primary_datetime() instanceof EE_Datetime) {
25
+			return;
26
+		}
27
+
28
+		$template_args = array(
29
+			'event_permalink' => '',
30
+			'event_name' => '',
31
+			'event_description' => '',
32
+			'event_start' => '',
33
+			'event_end' => '',
34
+			'event_attendance_mode' => '',
35
+			'event_status' => '',
36
+			'currency' => '',
37
+			'event_tickets' => array(),
38
+			'venue_name' => '',
39
+			'venue_url' => '',
40
+			'venue_locality' => '',
41
+			'venue_region' => '',
42
+			'venue_address' => '',
43
+			'event_image' => '',
44
+		);
45
+		$template_args['event_permalink'] = $event->get_permalink();
46
+		$template_args['event_name'] = $event->name();
47
+		$template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
48
+		// clone datetime so that date formats don't override those for the original datetime
49
+		$primary_datetime = clone $event->primary_datetime();
50
+		$template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM);
51
+		$template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM);
52
+		unset($primary_datetime);
53
+		switch ($event->status()) {
54
+			case EEM_Event::cancelled:
55
+				$event_status = 'EventCancelled';
56
+				break;
57
+			case EEM_Event::postponed:
58
+				$event_status = 'EventPostponed';
59
+				break;
60
+			default:
61
+				$event_status = 'EventScheduled';
62
+		}
63
+		$template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode';
64
+		$template_args['event_status'] = '"https://schema.org/' . $event_status . '"';
65
+		$template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
66
+		foreach ($event->tickets() as $original_ticket) {
67
+			// clone tickets so that date formats don't override those for the original ticket
68
+			$ticket = clone $original_ticket;
69
+			$ID = $ticket->ID();
70
+			$template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
+			$template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
+			$template_args['event_tickets'][ $ID ]['price'] = number_format(
73
+				$ticket->price(),
74
+				EE_Registry::instance()->CFG->currency->dec_plc,
75
+				EE_Registry::instance()->CFG->currency->dec_mrk,
76
+				''
77
+			);
78
+			switch ($ticket->ticket_status()) {
79
+				case 'TKO':
80
+					$availability = 'InStock';
81
+					break;
82
+				case 'TKS':
83
+					$availability = 'SoldOut';
84
+					break;
85
+				default:
86
+					$availability = null;
87
+					break;
88
+			}
89
+			$template_args['event_tickets'][ $ID ]['availability'] = $availability;
90
+			unset($ticket);
91
+		}
92
+		$VNU_ID = espresso_venue_id();
93
+		if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
94
+			$venue = EEH_Venue_View::get_venue($VNU_ID);
95
+			$template_args['venue_name'] = get_the_title($VNU_ID);
96
+			$template_args['venue_url'] = get_permalink($VNU_ID);
97
+			$template_args['venue_locality'] = $venue->city();
98
+			$template_args['venue_region'] = $venue->state_name();
99
+			$template_args['venue_address'] = $venue->address();
100
+			if ($venue->virtual_url() !== '') {
101
+				$template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode';
102
+			}
103
+			if ($venue->virtual_url() !== '' && $venue->address() !== '') {
104
+				$template_args['event_attendance_mode'] = 'MixedEventAttendanceMode';
105
+			}
106
+		}
107
+		$template_args['event_image'] = $event->feature_image_url();
108
+		$template_args = apply_filters(
109
+			'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
110
+			$template_args,
111
+			$event,
112
+			$VNU_ID
113
+		);
114
+		extract($template_args, EXTR_OVERWRITE);
115
+		include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
116
+	}
117
+
118
+
119
+	/**
120
+	 *    location
121
+	 *    The location of the event, organization or action.
122
+	 *    Should include the Venue name AND schema formatted address info
123
+	 *
124
+	 * @access public
125
+	 * @param string $location
126
+	 * @return string
127
+	 */
128
+	public static function location($location = null)
129
+	{
130
+		return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
131
+									  . $location
132
+									  . '</div>' : '';
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 *    name
139
+	 *    The name of the Event or Venue.
140
+	 *
141
+	 * @access public
142
+	 * @param string $name
143
+	 * @return string
144
+	 */
145
+	public static function name($name = null)
146
+	{
147
+		return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : '';
148
+	}
149
+
150
+
151
+
152
+	/**
153
+	 *    streetAddress
154
+	 *    The street address. For example, 1600 Amphitheatre Pkwy.
155
+	 *
156
+	 * @access public
157
+	 * @param EEI_Address $obj_with_address
158
+	 * @return string
159
+	 */
160
+	public static function streetAddress(EEI_Address $obj_with_address = null)
161
+	{
162
+		return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
163
+			? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 *    postOfficeBoxNumber
170
+	 *    The post office box number for PO box addresses.
171
+	 *
172
+	 * @access public
173
+	 * @param EEI_Address $obj_with_address
174
+	 * @return string
175
+	 */
176
+	public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null)
177
+	{
178
+		// regex check for some form of PO Box or P.O. Box, etc, etc, etc
179
+		if (
180
+			preg_match(
181
+				"/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
182
+				$obj_with_address->address2()
183
+			)
184
+		) {
185
+			return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
186
+				? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
187
+		} else {
188
+			return $obj_with_address->address2();
189
+		}
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 *    addressLocality
196
+	 *    The locality (city, town, etc). For example, Mountain View.
197
+	 *
198
+	 * @access public
199
+	 * @param EEI_Address $obj_with_address
200
+	 * @return string
201
+	 */
202
+	public static function addressLocality(EEI_Address $obj_with_address = null)
203
+	{
204
+		return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
205
+			? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 *    addressRegion
212
+	 *    The region (state, province, etc). For example, CA.
213
+	 *
214
+	 * @access public
215
+	 * @param EEI_Address $obj_with_address
216
+	 * @return string
217
+	 */
218
+	public static function addressRegion(EEI_Address $obj_with_address = null)
219
+	{
220
+		$state = $obj_with_address->state_name();
221
+		if (! empty($state)) {
222
+			return '<span itemprop="addressRegion">' . $state . '</span>';
223
+		} else {
224
+			return '';
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 *    addressCountry
232
+	 *    The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code.
233
+	 *
234
+	 * @access public
235
+	 * @param EEI_Address $obj_with_address
236
+	 * @return string
237
+	 */
238
+	public static function addressCountry(EEI_Address $obj_with_address = null)
239
+	{
240
+		$country = $obj_with_address->country_name();
241
+		if (! empty($country)) {
242
+			return '<span itemprop="addressCountry">' . $country . '</span>';
243
+		} else {
244
+			return '';
245
+		}
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 *    postalCode
252
+	 *    The postal code. For example, 94043.
253
+	 *
254
+	 * @access public
255
+	 * @param EEI_Address $obj_with_address
256
+	 * @return string
257
+	 */
258
+	public static function postalCode(EEI_Address $obj_with_address = null)
259
+	{
260
+		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
261
+																					  . $obj_with_address->zip()
262
+																					  . '</span>' : '';
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 *    telephone
269
+	 *    The telephone number.
270
+	 *
271
+	 * @access public
272
+	 * @param string $phone_nmbr
273
+	 * @return string
274
+	 */
275
+	public static function telephone($phone_nmbr = null)
276
+	{
277
+		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
278
+			: '';
279
+	}
280
+
281
+
282
+
283
+	/**
284
+	 *    URL
285
+	 *    URL of the item as a clickable link
286
+	 *
287
+	 * @access public
288
+	 * @param string $url        - the URL that the link will resolve to
289
+	 * @param string $text       - the text that will be used for the visible link
290
+	 * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
291
+	 * @return string (link)
292
+	 */
293
+	public static function url($url = null, $text = null, $attributes = array())
294
+	{
295
+		// Check the URL includes a scheme
296
+		$parsed_url = parse_url($url);
297
+		if (empty($parsed_url['scheme'])) {
298
+			$url = 'https://' . ltrim($url, '/');
299
+		}
300
+		$atts = '';
301
+		foreach ($attributes as $attribute => $value) {
302
+			$atts .= ' ' . $attribute . '="' . $value . '"';
303
+		}
304
+		$text = $text !== null && $text !== '' ? $text : esc_url($url);
305
+		return ! empty($url)
306
+			? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>'
307
+			: '';
308
+	}
309 309
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     public static function add_json_linked_data_for_event(EE_Event $event)
22 22
     {
23 23
         // Check we have a valid datetime for the event
24
-        if (! $event->primary_datetime() instanceof EE_Datetime) {
24
+        if ( ! $event->primary_datetime() instanceof EE_Datetime) {
25 25
             return;
26 26
         }
27 27
 
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
                 $event_status = 'EventScheduled';
62 62
         }
63 63
         $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode';
64
-        $template_args['event_status'] = '"https://schema.org/' . $event_status . '"';
64
+        $template_args['event_status'] = '"https://schema.org/'.$event_status.'"';
65 65
         $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
66 66
         foreach ($event->tickets() as $original_ticket) {
67 67
             // clone tickets so that date formats don't override those for the original ticket
68 68
             $ticket = clone $original_ticket;
69 69
             $ID = $ticket->ID();
70
-            $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
-            $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
-            $template_args['event_tickets'][ $ID ]['price'] = number_format(
70
+            $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
71
+            $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
72
+            $template_args['event_tickets'][$ID]['price'] = number_format(
73 73
                 $ticket->price(),
74 74
                 EE_Registry::instance()->CFG->currency->dec_plc,
75 75
                 EE_Registry::instance()->CFG->currency->dec_mrk,
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
                     $availability = null;
87 87
                     break;
88 88
             }
89
-            $template_args['event_tickets'][ $ID ]['availability'] = $availability;
89
+            $template_args['event_tickets'][$ID]['availability'] = $availability;
90 90
             unset($ticket);
91 91
         }
92 92
         $VNU_ID = espresso_venue_id();
93
-        if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
93
+        if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
94 94
             $venue = EEH_Venue_View::get_venue($VNU_ID);
95 95
             $template_args['venue_name'] = get_the_title($VNU_ID);
96 96
             $template_args['venue_url'] = get_permalink($VNU_ID);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
             $VNU_ID
113 113
         );
114 114
         extract($template_args, EXTR_OVERWRITE);
115
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
115
+        include EE_TEMPLATES.'json_linked_data_for_event.template.php';
116 116
     }
117 117
 
118 118
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public static function name($name = null)
146 146
     {
147
-        return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : '';
147
+        return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : '';
148 148
     }
149 149
 
150 150
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     public static function streetAddress(EEI_Address $obj_with_address = null)
161 161
     {
162 162
         return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
163
-            ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
163
+            ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : '';
164 164
     }
165 165
 
166 166
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
             )
184 184
         ) {
185 185
             return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
186
-                ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
186
+                ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : '';
187 187
         } else {
188 188
             return $obj_with_address->address2();
189 189
         }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     public static function addressLocality(EEI_Address $obj_with_address = null)
203 203
     {
204 204
         return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
205
-            ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
205
+            ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : '';
206 206
     }
207 207
 
208 208
 
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
     public static function addressRegion(EEI_Address $obj_with_address = null)
219 219
     {
220 220
         $state = $obj_with_address->state_name();
221
-        if (! empty($state)) {
222
-            return '<span itemprop="addressRegion">' . $state . '</span>';
221
+        if ( ! empty($state)) {
222
+            return '<span itemprop="addressRegion">'.$state.'</span>';
223 223
         } else {
224 224
             return '';
225 225
         }
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
     public static function addressCountry(EEI_Address $obj_with_address = null)
239 239
     {
240 240
         $country = $obj_with_address->country_name();
241
-        if (! empty($country)) {
242
-            return '<span itemprop="addressCountry">' . $country . '</span>';
241
+        if ( ! empty($country)) {
242
+            return '<span itemprop="addressCountry">'.$country.'</span>';
243 243
         } else {
244 244
             return '';
245 245
         }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      */
275 275
     public static function telephone($phone_nmbr = null)
276 276
     {
277
-        return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
277
+        return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>'
278 278
             : '';
279 279
     }
280 280
 
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
         // Check the URL includes a scheme
296 296
         $parsed_url = parse_url($url);
297 297
         if (empty($parsed_url['scheme'])) {
298
-            $url = 'https://' . ltrim($url, '/');
298
+            $url = 'https://'.ltrim($url, '/');
299 299
         }
300 300
         $atts = '';
301 301
         foreach ($attributes as $attribute => $value) {
302
-            $atts .= ' ' . $attribute . '="' . $value . '"';
302
+            $atts .= ' '.$attribute.'="'.$value.'"';
303 303
         }
304 304
         $text = $text !== null && $text !== '' ? $text : esc_url($url);
305 305
         return ! empty($url)
306
-            ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>'
306
+            ? '<a itemprop="url" href="'.esc_url_raw($url).'"'.$atts.'>'.$text.'</a>'
307 307
             : '';
308 308
     }
309 309
 }
Please login to merge, or discard this patch.