Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Forked from skyshab/example.php
Last active March 31, 2021 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc0ttkclark/e670113591b3cf1230dd2b2f6760865c to your computer and use it in GitHub Desktop.
Save sc0ttkclark/e670113591b3cf1230dd2b2f6760865c to your computer and use it in GitHub Desktop.
Allow all IAC attendees to view protected content
<?php
add_filter( 'tribe_tickets_shortcode_can_see_content', static function( $can_see_content, $filter_args ) {
// Only run our logic below if the user is logged in or if they cannot currently see the content.
if ( ! is_user_logged_in() || $can_see_content ) {
return $can_see_content;
}
$current_user = wp_get_current_user();
// Check to see if there are any attendees for the ticket ID(s) for this user email.
$args = [
// Only get one to improve performance.
'per_page' => 1,
'by' => [
'ticket' => $filter_args['ticket_ids'],
// purchaser_email is actually referencing the meta key which IAC uses too.
'purchaser_email' => $current_user->user_email,
],
];
$attendees = Tribe__Tickets__Tickets::get_event_attendees_by_args( $filter_args['post_id'], $args );
// Return whether they have matching attendee(s).
return ! empty( $attendees['attendees'] );
}, 100, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment