-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
512 lines (428 loc) · 20.6 KB
/
functions.php
File metadata and controls
512 lines (428 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<?php
// main plugin file
// phpcs:disable NamingConventions.ValidVariableName.VariableNotSnakeCase
// phpcs:disable WordPress.NamingConventions.ValidVariableName
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log
define( 'VENUE_CHECK_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'VENUE_CHECK_URL', plugin_dir_url( __FILE__ ) );
define( 'VENUE_CHECK_VERSION', 'version-2.4.2' );
// squarecandy-common files
require VENUE_CHECK_DIR_PATH . '/inc/sqcdy-common.php';
require VENUE_CHECK_DIR_PATH . '/inc/sqcdy-plugin.php';
// set up for event edit admin page
require VENUE_CHECK_DIR_PATH . 'inc/event-edit.php';
// set up for event edit admin page
require VENUE_CHECK_DIR_PATH . 'inc/venue-edit.php';
// class for calculating venue conflicts
require VENUE_CHECK_DIR_PATH . '/inc/class-venue-conflicts.php';
function venuecheck_scripts_styles( $hook ) {
global $post_type;
$venuecheck_post_types = array( 'tribe_events' );
if ( venuecheck_exclude_venues() ) {
$venuecheck_post_types[] = 'tribe_venue';
}
if ( ( 'post-new.php' !== $hook && 'post.php' !== $hook ) || ! in_array( $post_type, $venuecheck_post_types, true ) ) {
return;
}
/* REGISTER JS */
if ( defined( 'WP_DEBUG' ) ? WP_DEBUG : false ) {
wp_enqueue_script( 'venuecheck-scripts', VENUE_CHECK_URL . 'js/venue-check.js', array( 'jquery' ), VENUE_CHECK_VERSION, true );
} else {
wp_enqueue_script( 'venuecheck-scripts', VENUE_CHECK_URL . 'dist/js/venue-check.min.js', array( 'jquery' ), VENUE_CHECK_VERSION, true );
}
$localization = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'venuecheck-nonce' ),
'plugins_url' => plugin_dir_url( __FILE__ ),
'debug' => defined( 'WP_DEBUG' ) ? WP_DEBUG : false,
'batchsize' => 150, // max 250 - otherwise we hit max_input_vars 1000
'recurrence_warning_limit' => 300,
'multivenue' => false,
);
if ( class_exists( 'SQC_Multi_Venue' ) && SQC_Multi_Venue::is_enabled() ) {
$localization['multivenue'] = true;
$localization['fieldkey'] = SQC_Multi_Venue::get_field_key();
$localization['field_group'] = SQC_Multi_Venue::get_group_key();
$localization['container_id'] = '#multi-venue-container';
}
$localization = apply_filters( 'venuecheck_js_values', $localization );
/* LOCALIZE AJAX URL */
wp_localize_script( 'venuecheck-scripts', 'venuecheck', $localization );
/* REGISTER CSS */
wp_enqueue_style( 'venuecheck-styles', VENUE_CHECK_URL . 'dist/css/venue-check.min.css', array(), VENUE_CHECK_VERSION );
wp_enqueue_style( 'fontawesome', '//use.fontawesome.com/releases/v5.2.0/css/all.css', array(), '5.2.0' );
}
add_action( 'admin_enqueue_scripts', 'venuecheck_scripts_styles', 99999 );
add_action( 'wp_ajax_venuecheck_get_event_recurrences', 'venuecheck_get_event_recurrences' );
add_action( 'wp_ajax_venuecheck_check_venues', 'venuecheck_check_venues' );
add_action( 'wp_ajax_venuecheck_progress_bar', 'venuecheck_progress_bar' );
//include hidden events in query
add_filter( 'tribe_events_hide_from_upcoming_ids', 'venuecheck_include_hidden_events' );
function venuecheck_include_hidden_events( $ids ) {
$ids = array();
return $ids;
}
// check whether TEC has been fully migrated
add_action( 'plugins_loaded', 'venuecheck_tec_migrated' );
function venuecheck_tec_migrated() {
if ( ! defined( 'VENUE_CHECK_TEC_MIGRATED' ) ) {
$migrated = function_exists( 'tec_event_series' ) && tribe()->getVar( 'ct1_fully_activated' );
define( 'VENUE_CHECK_TEC_MIGRATED', $migrated );
}
return VENUE_CHECK_TEC_MIGRATED;
}
// Turn off Gutenberg for Events
// @TODO - create support for the block editor
// for now we're only supporting the classic editor, so force it for the tribe_events post type
add_filter( 'use_block_editor_for_post_type', 'prefix_disable_gutenberg', 20, 2 );
function prefix_disable_gutenberg( $current_status, $post_type ) {
if ( 'tribe_events' === $post_type ) {
return false;
}
return $current_status;
}
add_filter( 'venuecheck_upcoming_events_meta', 'venue_check_sqc_multi_venue_meta' );
function venue_check_sqc_multi_venue_meta( $meta_pivot ) {
if ( class_exists( 'SQC_Multi_Venue' ) && SQC_Multi_Venue::is_enabled() ) {
$meta_pivot['multiVenue'] = SQC_Multi_Venue::get_field_name();
}
return $meta_pivot;
}
// called via ajax
function venuecheck_get_event_recurrences() {
// Check for nonce security
if ( ! wp_verify_nonce( $_POST['nonce'], 'venuecheck-nonce' ) ) {
echo wp_json_encode( array( 'error' => 'error: wordpress nonce security check failed' ) );
die();
}
include 'src/class-tribe--events--pro--recurrence-venuecheck.php';
if ( isset( $_POST['post_data'] ) ) {
$postData = $_POST['post_data'];
} else {
echo wp_json_encode( array( 'error' => 'error: no post data' ) );
die();
}
if ( class_exists( 'Tribe__Events__Pro__Recurrence' ) ) {
parse_str( $postData, $vars );
$EventAllDay = 'no';
if ( array_key_exists( 'EventAllDay', $vars ) ) {
$EventAllDay = $vars['EventAllDay'];
}
$event_id = $vars['post_ID']; //not used
$startdate = $vars['EventStartDate'];
$starttime = $vars['EventStartTime'];
$eventTimezone = $vars['EventTimezone'];
$eventOffsetStart = $vars['_venuecheck_event_offset_start'];
$eventOffsetEnd = $vars['_venuecheck_event_offset_end'];
$enddate = $vars['EventEndDate'];
$endtime = $vars['EventEndTime'];
$duration = strtotime( "$enddate $endtime" ) - strtotime( "$startdate $starttime" );
$is_after = false; // $by_occurrence_count is same as $is_after
$recurrences = $vars['recurrence'];
$possible_next_pending = array();
$rulesArray = array();
$exclusionArray = array();
$recurrenceDates = array();
$recurrences1 = array( 'rules', 'exclusions' );
$earliest_date = strtotime( Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_earliest_date() );
$latest_date = strtotime( Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_latest_date() );
foreach ( $recurrences1 as $ruleType ) {
if ( array_key_exists( $ruleType, $recurrences ) ) {
foreach ( $recurrences[ $ruleType ] as &$recurrenceRules ) {
$type = $recurrenceRules['type'];
/*CIS
* Get_recurrence_parameters is a custom function created inside class Tribe__Events__Pro__Recurrence_VenueCheck in the file venuecheck_get_recurrence_parameters.php
* This function is used to create recuuring rules and recuuring exclusions array in proper format from post data.
* This function returns array of start time , duration , end and by-occurrence-count.
*/
$recurrence_parameters = Tribe__Events__Pro__Recurrence_VenueCheck::get_recurrence_parameters( $recurrenceRules, $duration, $enddate, $startdate, $EventAllDay );
$start_time = $recurrence_parameters['start-time'];
$end = (int) $recurrence_parameters['end'];
$duration = $recurrence_parameters['duration'];
$by_occurrence_count = $recurrence_parameters['by-occurrence-count'];
$recurrenceRules['type'] = 'Custom';
$recurrenceRules['custom']['type'] = $type;
$recurrenceRules['EventStartDate'] = gmdate( 'Y-m-d H:i:s', strtotime( "$startdate $start_time" ) );
$recurrenceRules['EventEndDate'] = gmdate( 'Y-m-d H:i:s', strtotime( "$enddate $endtime" ) );
/*CIS
* build_from is used to create an object from recurrence rules and exclusion array
*/
$rule = Tribe__Events__Pro__Recurrence__Series_Rules_Factory::instance()->build_from( $recurrenceRules, $ruleType );
if ( empty( $start_time ) ) {
$start_time = $starttime;
}
if ( isset( $recurrenceRules['custom']['same-time'] ) && 'yes' === $recurrenceRules['custom']['same-time'] && 'yes' === $EventAllDay ) {
$start_time = '00:00';
}
$recurrenceObj = new Tribe__Events__Pro__Recurrence( strtotime( "$startdate $start_time" ), $end, $rule, $by_occurrence_count, $event = null, $start_time, $duration );
$recurrenceObj->setMinDate( $earliest_date );
$recurrenceObj->setMaxDate( $latest_date );
/*CIS
* getDates gives output as dates array of timestamp and duration
* getDates function is existing function of class Tribe__Events__Pro__Recurrence
*/
$recurrenceDates[ $ruleType ] = $recurrenceObj->getDates();
if ( 'rules' === $ruleType ) {
$rulesArray = array_merge( $rulesArray, $recurrenceDates[ $ruleType ] );
} else {
$exclusionArray = array_merge( $exclusionArray, $recurrenceDates[ $ruleType ] );
}
}
}
}
$uniqueRules = array();
foreach ( $rulesArray as $rulearr ) {
$uniqueRules[ join( '|', $rulearr ) ] = $rulearr;
}
/* CIS
$rulesArray has all recurring rules dates array */
$rulesArray = array_values( $uniqueRules );
$uniqueExclusion = array();
foreach ( $exclusionArray as $excarr ) {
$uniqueExclusion[ join( '|', $excarr ) ] = $excarr;
}
/* CIS
$exclusionArray has all recurring exclusion dates array */
$exclusionArray = array_values( $uniqueExclusion );
/* CIS
Remove exclusion dates from recurring rules dates and get the dates on which event will be held
*/
$timezone_string = get_option( 'timezone_string' );
$removeExcObj = new Tribe__Events__Pro__Recurrence__Exclusions( $timezone_string );
/*CIS
remove_exclusions removes the exclusion dates from $rulesArray dates and get the final dates of event .
*/
$to_create = $removeExcObj->remove_exclusions( $rulesArray, $exclusionArray );
foreach ( $to_create as $key => $value ) {
$to_create[ $key ]['eventStart'] = gmdate( 'Y-m-d H:i:s', $to_create[ $key ]['timestamp'] );
$to_create[ $key ]['eventEnd'] = gmdate( 'Y-m-d H:i:s', $to_create[ $key ]['timestamp'] + $to_create[ $key ]['duration'] );
$to_create[ $key ]['eventTimezone'] = $eventTimezone;
$to_create[ $key ]['eventOffsetStart'] = $eventOffsetStart;
$to_create[ $key ]['eventOffsetEnd'] = $eventOffsetEnd;
unset( $to_create[ $key ]['timestamp'] );
unset( $to_create[ $key ]['duration'] );
}
echo wp_json_encode( $to_create );
wp_die();
} else {
add_action( 'admin_notices', 'events_calendar_pro_not_loaded' );
}
}
/**
* Internal function to get upcoming events
* so we can check if they overlap with the event being edited
* @TODO: currently we're getting all events starting after "now"
* however we should be getting all events ENDING after now to avoid missing long events that have already started
*/
function venuecheck_get_upcoming_events() {
global $wpdb;
$now = wp_date( 'Y-m-d ' ) . '00:00:01';
$migrated = venuecheck_tec_migrated();
// use mysql pivot technique to ouput an object with the postmeta we need
$pivot_meta = array(
// column name => meta_key
'_EventTimezone' => '_EventTimezone',
'_venuecheck_event_offset_start' => '_venuecheck_event_offset_start',
'_venuecheck_event_offset_end' => '_venuecheck_event_offset_end',
'_EventVenueID' => '_EventVenueID',
'multiVenue' => 'multiVenue',
);
if ( ! $migrated ) {
$pivot_meta['_EventStartDate'] = '_EventStartDate';
$pivot_meta['_EventEndDate'] = '_EventEndDate';
}
$pivot_meta = apply_filters( 'venuecheck_upcoming_events_meta', $pivot_meta );
$pivot_meta_case = array();
foreach ( $pivot_meta as $key => $meta_key ) {
$pivot_meta_case[] = "MAX(CASE WHEN m.meta_key='$meta_key' then m.meta_value end) $key";
}
$pivot_meta = implode( "', '", array_values( $pivot_meta ) );
$pivot_meta_case = implode( ', ', $pivot_meta_case );
/* we'll end up with something like:
JOIN ( SELECT m.post_id,
MAX(CASE WHEN m.meta_key='_EventTimezone' then m.meta_value end) _EventTimezone,
MAX(CASE WHEN m.meta_key='_venuecheck_event_offset_start' then m.meta_value end) _venuecheck_event_offset_start,
MAX(CASE WHEN m.meta_key='_venuecheck_event_offset_end' then m.meta_value end) _venuecheck_event_offset_end,
MAX(CASE WHEN m.meta_key='_EventVenueID' then m.meta_value end) _EventVenueID,
MAX(CASE WHEN m.meta_key='additional_venues' then m.meta_value end) multiVenue
FROM 4Bjov1_postmeta m WHERE m.meta_key IN ( '_EventTimezone', '_venuecheck_event_offset_start', '_venuecheck_event_offset_end', '_EventVenueID', 'additional_venues' ) GROUP by post_id ) q
*/
if ( $migrated ) {
$pivot_sql = "SELECT (o.occurrence_id + 10000000) as 'occurrence_id', o.start_date as _EventStartDate, o.end_date as _EventEndDate, p.ID, p.ID as parent_event, p.post_title, q.* FROM $wpdb->posts p INNER JOIN $wpdb->tec_occurrences o ON p.ID = o.post_id JOIN ( SELECT m.post_id, $pivot_meta_case FROM $wpdb->postmeta m WHERE m.meta_key IN ( '$pivot_meta' ) GROUP by post_id ) q ON p.ID = q.post_id WHERE ( CAST(o.start_date_utc AS DATETIME) > '$now' ) AND p.post_type = 'tribe_events' AND ( p.post_status IN ('publish', 'future', 'draft', 'pending', 'auto-draft' ,'inherit', 'private') ) GROUP BY o.occurrence_id ORDER BY p.post_date DESC";
} else {
$pivot_sql = "SELECT p.ID as 'occurrence_id', p.ID, p.post_parent as parent_event, p.post_title, q.* FROM $wpdb->posts p JOIN ( SELECT m.post_id, $pivot_meta_case FROM $wpdb->postmeta m WHERE m.meta_key IN ( '$pivot_meta' ) GROUP by post_id ) q ON p.ID = q.post_id AND p.post_type = 'tribe_events' AND p.post_status IN ('publish', 'future', 'draft', 'pending', 'auto-draft' ,'inherit', 'private') AND q._EventStartDate >= '$now'";
}
$started = microtime( true );
//phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$pivot_results = $wpdb->get_results( $pivot_sql, OBJECT );
$upcomingEvents = $pivot_results;
if ( WP_DEBUG ) {
$ended = microtime( true );
$difference = $ended - $started;
$query_time = number_format( $difference, 10 );
error_log( $pivot_sql );
error_log( 'query time: ' . $query_time );
}
return $upcomingEvents;
}
/**
* Calculate the padded start & end times for an event
*
* @param array|object $event with start/end date and start/end offset
* @param string $imezone
* @return array|false False on failure.
* $OffsetStart DateTime object
* $OffsetStart DateTime object
*/
function venuecheck_get_offset_dates( $event, $timezone ) {
if ( is_object( $event ) ) {
$start_date = $event->_EventStartDate;
$end_date = $event->_EventEndDate;
$offset_start = $event->_venuecheck_event_offset_start;
$offset_end = $event->_venuecheck_event_offset_end;
} elseif ( is_array( $event ) ) {
$start_date = $event['eventStart'];
$end_date = $event['eventEnd'];
$offset_start = $event['eventOffsetStart'];
$offset_end = $event['eventOffsetEnd'];
} else {
return;
}
$start = new DateTime( $start_date, new DateTimeZone( $timezone ) );
$end = new DateTime( $end_date, new DateTimeZone( $timezone ) );
// subtract offset from start (a.k.a "setup time")
if ( ! empty( $offset_start ) ) {
$eventOffsetStart = 'PT' . $offset_start . 'M';
$start->sub( new DateInterval( $eventOffsetStart ) );
}
// add offset to end (a.k.a. "cleanup time")
if ( ! empty( $offset_end ) ) {
$eventOffsetEnd = 'PT' . $offset_end . 'M';
$end->add( new DateInterval( $eventOffsetEnd ) );
}
$offset_array = array(
'OffsetStart' => $start,
'OffsetEnd' => $end,
);
return $offset_array;
}
function venuecheck_check_venues() {
// Check for nonce security
if ( ! wp_verify_nonce( $_POST['nonce'], 'venuecheck-nonce' ) ) {
echo wp_json_encode( array( 'error' => 'error: wordpress nonce security check failed - ' . $_POST['nonce'] ) );
die();
}
$upcomingEvents = get_cached_upcoming_events();
//end events query
if ( WP_DEBUG ) {
error_log( '**************************************************************************' );
error_log( 'Venue Check upcoming events: ' . count( $upcomingEvents ) );
}
$venuecheck_conflicts = new Venue_Conflicts();
$defaultTimezone = get_option( 'timezone_string' );
//event confict checking
if ( isset( $_POST ) ) {
/*
* CONFLICT: (StartA < EndB) and (EndA > StartB)
*
* A conflict occurs if:
* the start of the new event is before the end of the existing event
* AND the end of the new event is after the start of the existing event
*
* This accounts for overlaps at the beginning of the existing event; overlaps at the end of the existing event; complete overlap.
*
* data format:
* {eventStart: "2018-05-14 8:00:00", eventEnd: "2018-05-14 17:00:00", eventTimezone: "America/New_York", eventOffsetStart: "0", eventOffsetEnd: "0"}
*/
// new event dates
$event_recurrences = $_POST['event_recurrences'];
$postID = $_POST['postID'];
$total_count = $_POST['total_count'];
$batch_size = $_POST['batch_size'];
$batch_count = $_POST['batch_count'];
$loop_count = 0;
if ( WP_DEBUG ) {
error_log( '* Venue Check event recurrences for post id ' . $postID . ': ' . $total_count );
error_log( '* Venue Check batch: ' . $batch_count . ' of ' . $batch_size );
}
foreach ( $event_recurrences as $k => $event_recurrence ) {
++$loop_count;
$current_count = ( $batch_count * $batch_size ) + $loop_count;
$timezone = $event_recurrence['eventTimezone'];
$offsetDatesA = venuecheck_get_offset_dates( $event_recurrence, $timezone );
$startA = $offsetDatesA['OffsetStart'];
$endA = $offsetDatesA['OffsetEnd'];
if ( WP_DEBUG ) {
error_log( '*********************************' );
error_log( '* * Venue Check event recurrence: ' . $event_recurrence['eventStart'] . ' to ' . $event_recurrence['eventEnd'] );
}
//upcoming event dates
foreach ( $upcomingEvents as $k => $upcomingEvent ) {
if ( ! empty( $upcomingEvent->_EventTimezone ) ) {
$timezone = $upcomingEvent->_EventTimezone;
} else {
$timezone = $defaultTimezone;
}
$offsetDatesB = venuecheck_get_offset_dates( $upcomingEvent, $timezone );
$startB = $offsetDatesB['OffsetStart'];
$endB = $offsetDatesB['OffsetEnd'];
if ( WP_DEBUG ) {
error_log( '* * * * * Checking: ' . $upcomingEvent->ID . ': (' . $upcomingEvent->post_title . ') (parent ' . $upcomingEvent->parent_event . ') (occurence ' . $upcomingEvent->occurrence_id . ') ' . $upcomingEvent->_EventStartDate . ' to ' . $upcomingEvent->_EventEndDate );
}
// compare dates to find conflicts
if ( $startA < $endB && $endA > $startB ) {
// check that the upcoming event isn't our event, or a recurrence of our event
if ( $upcomingEvent->ID !== $postID && $upcomingEvent->parent_event !== $postID ) {
if ( WP_DEBUG ) {
error_log( '* * * * * * Conflict in venue ' . $upcomingEvent->multiVenue );
}
$venues = $upcomingEvent->multiVenue ? maybe_unserialize( $upcomingEvent->multiVenue ) : array( $upcomingEvent->_EventVenueID );
foreach ( $venues as $venue_id ) {
$EventVenueID = (int) $venue_id;
$venuecheck_conflicts->add_venue( $upcomingEvent, $startB, $endB, $EventVenueID );
}
}
}
} //end foreach $upcomingEvents
} //end foreach $event_recurrences
$venuecheck_conflicts->filter();
if ( WP_DEBUG ) {
error_log( '* Venuecheck batch done.' );
error_log( '**************************************************************************' );
error_log( '**************************************************************************' );
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
error_log( print_r( $venuecheck_conflicts, true ) );
}
echo wp_json_encode( $venuecheck_conflicts->conflicts );
}
wp_die();
}
// make sure not to try to grab the WPORG version
add_filter( 'gu_override_dot_org', 'venue_check_gu_override_dot_org' );
function venue_check_gu_override_dot_org() {
return array( 'venue-check/plugin.php' );
}
function get_cached_upcoming_events() {
$cache = tribe( 'cache' );
$u_events = $cache->get_transient( 'tribe_venue_check_upcoming_events', 'save_post' ); // by adding 'tribe_' at the start we allow these transients to be cleaned up by TEC
if ( is_array( $u_events ) ) {
if ( WP_DEBUG ) {
error_log( 'USING CACHE' );
}
return $u_events;
}
$u_events = venuecheck_get_upcoming_events();
if ( WP_DEBUG ) {
error_log( 'SETTING CACHE' );
}
$cache->set_transient( 'tribe_venue_check_upcoming_events', $u_events, HOUR_IN_SECONDS, 'save_post' ); // NON_PERSISTENT, should be cleaned up by next 'tribe_schedule_transient_purge' run
return $u_events;
}
// allow exclude venues setting to be set e.g. in the theme
function venuecheck_exclude_venues() {
return apply_filters( 'venuecheck_exclude_venues', false );
}
// check whether a venue is "excluded"
function venuecheck_is_excluded_venue( $venue_id ) {
return get_post_meta( $venue_id, 'venuecheck_exclude_venue', true );
}